How to use Accounts.onEmailVerificationLink?

I am a bit confused on how to use Accounts.onEmailVerificationLink. The documents are somewhat ambiguous:

Accounts.onEmailVerificationLink (callback)

Register a function to call when an email click is verified in an email sent to Accounts.sendVerificationEmail. This function should be called in the top-level code, and not inside Meteor.startup ().

What exactly does this function mean, a callback, or Accounts.onEmailVerificationLink itself?

In any case, 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.
+4
source share
4 answers

(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, , .

+3
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();

    });
  });
}
-1

, , "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();
        }
    });
});

, .

-1

, : ui package,

meteor remove accounts:ui

and then use the callback to add your own logic

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

All Articles