0

Meteor ve autoform ile basit giriş formu oluşturmaya çalışıyorum ama istisna aldım.autoform tarafından oluşturulan giriş formu ile istisna (type = "normal")

Bu üretilmesi formu için benim şeması yer almaktadır:

FormSchemasLoginUsers = new SimpleSchema({ 
    email: { 
     type: String, 
     regEx: SimpleSchema.RegEx.Email 
    }, 
    password: { 
     type: String, 
     min: 6, 
     autoform: { 
      type: "password" 
     } 
    } 
}); 

Ve bu benim form şablonu: Ben bu kancalarla kullanıcı girişi işlemeye çalışır

<template name="Login"> 
    {{> quickForm id="loginUserForm" schema="FormSchemasLoginUsers" type="normal" }} 
</template> 

:

Template.Login.onRendered(function() { 
    AutoForm.addHooks('loginUserForm', 
     { 
      onSubmit: function (doc) { 
       console.log(doc); 
       Meteor.loginWithPassword(doc.email, doc.password, function(err) { 
        console.log(err); 
        if (err) 
        { 
         this.done(new Error("Login failed")); 
        } 
        this.done(); 
       }); 
       return false; 
      }, 
      onSuccess: function(result) { 
       Router.go("home_private"); 
      }, 
      onError: function(error) { 
       console.log("Error: ", error); 
      } 
     } 
    ); 
}); 

Ancak bu hatayı bir konsol konsolunda buldum:

Exception in delivering result of invoking 'login': .onSubmit/<@http://localhost:5000/app/client/views/login/login.js?b8771614cf48d3759cf0d764e51a0693caf23c81:18:5 
Meteor.loginWithPassword/<[email protected]://localhost:5000/packages/accounts-password.js?8eae27e32c4d1bc1194f7c6dd2aaed1e33a88499:91:21 
Ap.callLoginMethod/loginCallbacks<@http://localhost:5000/packages/accounts-base.js?7dabd814506e384c709f8bf707377955f9814129:612:5 
_.once/<@http://localhost:5000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:794:14 
Ap.callLoginMethod/logged[email protected]://localhost:5000/packages/accounts-base.js?7dabd814506e384c709f8bf707377955f9814129:720:5 
Meteor.bindEnvironment/<@http://localhost:5000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:17 
[email protected]://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3500:7 
[email protected]://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3520:5 
[email protected]://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:4631:7 
Connection/[email protected]://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3365:7 
._launchConnection/self.socket.onmessage/<@http://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:2734:11 
[email protected]://localhost:5000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:149:7 
._launchConnection/[email protected]://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:2733:9 
[email protected]://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:173:9 
[email protected]://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:1158:5 
[email protected]://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:1216:13 
SockJS.websocket/[email protected]://localhost:5000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:1363:9 

meteor....a1802d4 (line 880) 

Ayrıca, Meteor.user() kullanarak oturum açmanın bittiğini veya olmadığını ve kullanıcı girişinin başarıyla tamamlandığını kontrol ediyorum.

Sorun nedir? Bunun için iki günüm var ama sorun bulamıyorum.

cevap

1

Bu sorunu alıyorsunuz çünkü 'u Meteor.loginWithPassword(user, password, [callback]) içine çağırıyorsunuz ve bu da this değerinin yanlış bir şekilde bağlanmasına neden oluyor. ES6 arrow functions ya da var self = this;'u tanımlayabilir ve this.done(); yerine self.done();'u arayabilirsiniz. Örneğin

:

AutoForm.addHooks('loginUserForm', { 
    onSubmit: function(doc) { 
    console.log(doc); 
    Meteor.loginWithPassword(doc.email, doc.password, (err) => { 
     console.log(err); 
     if (err) this.done(new Error("Login failed")); 
     this.done(); 
    }); 
    return false; 
    }, 
    onSuccess: function(result) { 
    Router.go("home_private"); 
    }, 
    onError: function(error) { 
    console.log("Error: ", error); 
    } 
}); 
+0

Ah adam hayatımı kurtarmak. Bu '' 'hakkında düşünmedim. Ben ES6 stiline ve her şeye dönüşüyorum. Tekrar oynattığınız için teşekkürler. – b24

İlgili konular