【问题标题】:How to use Accounts.onEmailVerificationLink?如何使用 Accounts.onEmailVerificationLink?
【发布时间】:2015-02-14 13:11:12
【问题描述】:

我对如何使用 Accounts.onEmailVerificationLink 有点困惑。
文档有些模棱两可:

Accounts.onEmailVerificationLink(回调)

注册一个函数以在单击电子邮件验证链接时调用 在 Accounts.sendVerificationEmail 发送的电子邮件中。 这个功能 应该在顶层代码中调用,而不是在 Meteor.startup() 中调用。

“这个函数”、回调或Accounts.onEmailVerificationLink 本身到底是什么意思?

不管怎样,不管我把东西放在哪里,我总是在浏览器控制台上得到这个错误信息:

Accounts.onEmailVerificationLink was called more than once. Only one callback added will be executed.

【问题讨论】:

  • 即使Accounts.onEmailVerificationLink() 函数为空,我也会收到Accounts.onEmailVerificationLink was called more than once. Only one callback added will be executed. 错误。你想清楚了吗?
  • 我刚刚删除了通话,账户验证仍然有效,所以它必须由用户帐户处理:我猜是包。
  • 没有,终于找到了:在accounts:ui包里(当然……)

标签: meteor meteor-accounts


【解决方案1】:

如果你使用集合挂钩 (https://atmospherejs.com/matb33/collection-hooks),你可以这样做:

Meteor.users.after.update(function (userId, doc, fieldNames, modifier, options) {
  if (!!modifier.$set) {
    //check if the email was verified
    if (modifier.$set['emails.$.verified'] === true) {
      //do something
    }
  }
});

在花了一些时间尝试连接 onMailVerificationLink 之后,我发现上面的内容不那么挑剔了。

【讨论】:

    【解决方案2】:
    if (Meteor.isClient) {
      //Remove the old callback
      delete Accounts._accountsCallbacks['verify-email'];
      Accounts.onEmailVerificationLink(function (token, done) {
        Accounts.verifyEmail(token, function (error) {
          if (!error) {
            //Do stuff
          }
          done();
    
        });
      });
    }
    

    【讨论】:

      【解决方案3】:

      它所指的功能是“onEmailVerificationLink”。它需要在一些高级客户端代码中。 使用下面的代码,我可以在验证电子邮件后更改功能:

      // Override the method that fires when the user clicks the link in the verification email
      // for our own behavior.
      Accounts.onEmailVerificationLink((token, done) => {
          Accounts.verifyEmail(token, (err) => {
              if (err) {
                  console.log("Error: ", err);
              } else {
                  console.log("Success");
                  // Do whatever you want to on completion, the
                  // done() call is the default one.
                  done();
              }
          });
      });
      

      控制台消息仍然出现,但被覆盖的代码运行。

      【讨论】:

        【解决方案4】:

        如果可以的话,你应该删除accounts:ui包,它也是使用它

        meteor remove accounts:ui
        

        然后使用回调添加自己的逻辑

        Accounts.onEmailVerificationLink(function(token, done) {
          //your own logic
          //Accounts.verifyEmail(token, (error){
          //  if(!error) {
          //    alert('done!');
          //  }
          //});
        });
        

        【讨论】:

        • 我不知道这个特定的回调,但不应该在某个时候调用 done 吗?
        猜你喜欢
        • 2017-05-27
        • 2019-04-10
        • 2016-08-09
        • 1970-01-01
        • 1970-01-01
        • 2018-07-29
        • 1970-01-01
        • 1970-01-01
        • 2014-08-19
        相关资源
        最近更新 更多