Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Accounts.onEmailVerificationLink?

I'm a bit confused about how to use Accounts.onEmailVerificationLink.
The docs are somewhat ambiguous:

Accounts.onEmailVerificationLink(callback)

Register a function to call when an email verification link is clicked in an email sent by Accounts.sendVerificationEmail. This function should be called in top-level code, not inside Meteor.startup().

What is meant exactly by "this function", the callback, or Accounts.onEmailVerificationLink itself?

Anyway, no matter where I put things, I always get this error message on the browser console:

Accounts.onEmailVerificationLink was called more than once. Only one callback added will be executed.
like image 684
willemx Avatar asked Nov 27 '22 06:11

willemx


1 Answers

If you use collection hooks (https://atmospherejs.com/matb33/collection-hooks), you can do something like this:

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
    }
  }
});

After spending some time trying to hook into the onMailVerificationLink, I find the above to be much less finicky.

like image 114
Julian K Avatar answered Dec 04 '22 03:12

Julian K