在我的服务器上,我设置的帐户需要电子邮件验证并发送验证电子邮件:
Accounts.config({sendVerificationEmail: true, forbidClientAccountCreation: false});
我在网上读到,一旦点击验证链接,就会将用户重定向到网络应用程序的主页。
在该主页上,我 try catch 第一次得到确认的时间,因为我想在第一次电子邮件得到验证并且用户得到身份验证时向 MONGO DB 添加一些条目。
所以我尝试通过这样做在客户端获得此确认:
Template.home.created = function(){
if (Accounts._verifyEmailToken) {
Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
if (err != null) {
if (err.message = 'Verify email link expired [403]') {
console.log('Sorry this verification link has expired.')
}
} else {
console.log('Thank you! Your email address has been confirmed.')
}
});
}
}
不幸的是,我从来没有console.log('谢谢!您的电子邮件地址已被确认。')
登录控制台......
即使在我第一次点击它之后,我总是会收到 console.log('抱歉,此验证链接已过期。')
。
我在这里缺少什么???
如何在电子邮件首次验证时调用函数???
谢谢。
最佳答案
您的错误消息验证是错误的:您正在执行分配而不是条件检查。
if (err.message = 'Verify email link expired [403]') // WRONG!
if (err.message == 'Verify email link expired [403]') // this is a condition
我建议你输出err.message的内容继续前进,因为它可能与链接过期根本没有关系!
Template.home.created = function(){
if (Accounts._verifyEmailToken) {
Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
if (err != null) {
console.log(err.message);
} else {
console.log('Thank you! Your email address has been confirmed.')
}
});
}
}
关于javascript - Meteor:对电子邮件验证确认执行某些操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32732683/