Meteor:对电子邮件验证确认执行某些操作

2024-01-08

在我的服务器上,我设置帐户需要电子邮件验证并发送验证电子邮件:

Accounts.config({sendVerificationEmail: true, forbidClientAccountCreation: false});

我在网上的某个地方读到,一旦点击验证链接,就会将用户重定向到网络应用程序的主页。

在该主页上,我尝试捕获第一次得到确认的时间,因为我想在第一次电子邮件得到验证并且用户得到身份验证时向 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('Thank you! Your email address has been confirmed.')登录控制台...... 我总是得到console.log('Sorry this verification link has expired.')即使在我第一次点击它之后。

我在这里缺少什么???

如何在电子邮件第一次验证时调用一个函数???

谢谢。


您的错误消息验证是错误的:您正在执行分配而不是条件检查。

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.')
      }
    });
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Meteor:对电子邮件验证确认执行某些操作 的相关文章

随机推荐