我正在尝试为用户设置电子邮件验证 . 我正在使用 useraccounts:core
的 enforceEmailVerification
,我的服务器上有以下内容
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
中并不是一个好主意,因为用户还没有"exist" .如果您正在使用某种方法,则可以在创建用户时返回用户ID,然后再发送电子邮件,如下所示:
您需要将sendVerificationEmail放在Accounts.createUser中并设置超时