Gotrue-js password recovery

HI,

I have problems to understand how can I do a password recovery.

After I request the password reset, I receive an email with the token.

https://www.myapp.com/#recovery_token=XXXXXXXXXXXXXXXXXXX

After clicking the link, I check if there is a hash and load an overlay with a small form, but now I’m stuck. How can I reset the password?

In the docs I can only find this, but where I have to store the new password?

auth
  .recover(token)
  .then(response =>
    console.log("Logged in as %s", JSON.stringify({ response }))
  )
  .catch(error => console.log("Failed to verify recover token: %o", error));

gregor

did more research

does this recovery sends me back the user and with this user I can update the password, with this snippet?

const user = auth.currentUser();

user
  .update(password: "password" })
  .then(user => console.log("Updated user %s", user))
  .catch(error => {
    console.log("Failed to update user: %o", error);
    throw error;
  });

ok this works for me

after laoding the page I check for the token and use auth.recover and redirect to my password-reset page

if(window.location.hash) {
   const token_recovery = window.location.hash.split('recovery_token=')[1]
   if(token_recovery) {
      console.log('recover_token')
      auth
        .recover(token_recovery, true)
        .then(response => {
          console.log(response)
          app.router.push('/password-reset')
        })
        .catch((error) => {
          console.log(error)
        })
    }
}

and when I check my auth object on the password-reset page, I have a user I can use for the update

mounted() {
    console.log(this.$auth.currentUser())
},
methods: {
  update() {
    this.$auth
      .currentUser()
      .update({password: this.password})
      .then(response => {
        console.log(response)
      })
      .catch(error => {
        console.log(error)
        throw error
      })
  }
}
2 Likes