2015-02-06 94 views
0

我正在嘗試爲用戶設置電子郵件驗證。我使用useraccounts:coreenforceEmailVerification和我的服務器流星用戶帳戶電子郵件驗證

Accounts.onCreateUser(function(options, user) { 
    var userId = user._id; 
    Accounts.sendVerificationEmail(userId); 

    if(options.profile.invite){ 
    Invites.remove({_id: options.profile.invite}); 
    } 

    user.profile = options.profile 

    return user; 
}); 

上,我有以下當我嘗試註冊一個用戶,我得到以下服務器錯誤

I20150206-18:12:08.648(-5)? Exception while invoking method 'ATCreateUserServer' Error: Can't find user 
I20150206-18:12:08.648(-5)?  at Object.Accounts.sendVerificationEmail (packages/accounts-password/password_server.js:562:1) 
I20150206-18:12:08.648(-5)?  at Meteor.methods.deleteAccount.userId (app/server/accountsMeld.js:12:12) 
I20150206-18:12:08.648(-5)?  at Object.Accounts.insertUserDoc (packages/accounts-base/accounts_server.js:1024:1) 
I20150206-18:12:08.649(-5)?  at createUser (packages/accounts-password/password_server.js:693:1) 
I20150206-18:12:08.649(-5)?  at Object.Accounts.createUser (packages/accounts-password/password_server.js:751:1) 
I20150206-18:12:08.649(-5)?  at [object Object].Meteor.methods.ATCreateUserServer (packages/useraccounts:core/lib/methods.js:66:1) 
I20150206-18:12:08.649(-5)?  at [object Object].methodMap.(anonymous function) (packages/meteorhacks:kadira/lib/hijack/wrap_session.js:182:1) 
I20150206-18:12:08.649(-5)?  at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599:1) 
I20150206-18:12:08.649(-5)?  at packages/ddp/livedata_server.js:648:1 
I20150206-18:12:08.649(-5)?  at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1) 

回答

2

我碰到這個問題也來了並根據此:https://github.com/alanning/meteor-roles/issues/35#issuecomment-40674250,

因爲用戶還沒有「存在」,所以將Accounts.sendVerificationEmail(userId);放在Accounts.onCreateUser之內並不是一個好主意。

如果你使用,你可以返回,當用戶在創建用戶ID的方法,那麼以後發送電子郵件,就像這樣:

var userID = Accounts.createUser(options, callback); 
Accounts.sendVerificationEmail(userID); 
+0

唉,我也得到一個錯誤,因爲createuser還沒有回調。 – corvid 2015-03-10 16:06:58

+0

@corvid回調函數是你自己定義的一個函數,雖然你不必在那裏有一個函數。 – reoh 2015-03-11 00:46:57

1

你需要把裏面sendVerificationEmail和Accounts.createUser設置timeout

Accounts.onCreateUser(function(options, user) { 

// we wait for Meteor to create the user before sending an email 
Meteor.setTimeout(function() { 
    Accounts.sendVerificationEmail(user._id); 
}, 2 * 1000); 

return user; 
}); 
相關問題