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

Hi! i used Accounts.onResetPasswordLink

Accounts.onResetPasswordLink(token => {
  > Display prompt
  Accounts.resetPassword(token, newPassword, err => {
    ...
  });
});

Then i got log in console =>
Accounts.onResetPasswordLink was called more than once. Only one callback added will be executed.

How can i avoid this ? maybe i use it the bad way or is in the wrong part of my code ?

How are you calling this code?

Can you provide more?

For this error to be thrown, you’re somehow calling this method twice.

I think you could very well ignore that part of the documentation. Please read this thread: How to use Accounts.onResetPasswordLink with React? - #6 by sashko specifically the comment from Sashko.

The way I used to do it before I moved all projects to Passwordless:

  • Have a route for the password reset and open a component / view something like:
    { path: '/reset-password/:token', component: ResetPasswordPage }
  • ResetPasswordPage is your new password form.
  • Do all client-side validations for your password… too short, too long, at least 1 alpha etc etc
  • Example of on submit function for your password form. This was done in React:
const handlePasswordSubmit = () => {
    const { token } = match?.params // token from your link. Your route was defined as .../:token
   // at this stage password was already tested for compliancy and password and retype password are equal.

   // instead of console log use your user on-screen notifications system
    Accounts.resetPassword(token, pass, err => {
      if (err) {
        console.log('It looks that this link has already been used and is now expired.')
      } else {
        console.log('Your password has been changed. Please log in with the new password!')
      }
    })
    history.push('/signin') // send the user to the login screen
  }

As the docs states, the method onResetPasswordLink registers a function to call when a reset password link is clicked, and it should be called in top-level code.

So inside of your /client/main.js (or starting point of your client), you can call it.

Where are you calling this method?

Hi! its called in top level and not in a meteor.startup()