1

I tried to create a reset password page. But if I apply the action code it shows me, that the code is invalid. But it should be valid. So I guess the way I do it is wrong?! I also have a verify email page, where I also using applyActionCode, there it works fine. And yes I'm 100% sure that the oobCode must be correct.

console.log(this.$route.query.oobCode.toString())
firebase.auth().applyActionCode(this.$route.query.oobCode.toString()).then(
    (user) => {
        cosnole.log('user', user)
        user.updatePassword(this.password).then(
            function(user) {
                console.log('password updated')
            }).catch(
            function(err) {
                console.log(err.message)
            }
        )
    }).catch(
    function(err) {
        console.log(err.message)
    }
)
2
  • 1
    Can you show the error message you are getting in your question? Commented Feb 9, 2018 at 9:53
  • The action code is invalid. This can happen if the code is malformed, expired, or has already been used. Commented Feb 9, 2018 at 16:32

1 Answer 1

4

There are a few things to understand when resetting a users password using firebase auth using your example.

applyActionCode returns firebase.Promise containing void.

The user comes from firebase.auth().currentUser of a recently authenticated user. updatePassword also returns firebase.Promise containing void

There is the option of using confirmPasswordReset that will combine the two above.

Important: The code must be the valid operation type (PASSWORD_RESET) returned from an email spawned by the sendPasswordResetEmail method

The code would be something similiar to the following

firebase.auth().applyActionCode(this.$route.query.oobCode.toString())
  .then( () => {
    const user = firebase.auth().currentUser
    user.updatePassword(this.password).then(
      () => {
        console.log('password updated')
      })
   .catch(
     error => {
       console.log(error.code, error.message)
     })        
  }
  .catch(error => {
    console.log(error.code, error.message)
  })

or confirmPasswordReset

firebase.auth().confirmPasswordReset(this.$route.query.oobCode.toString(), this.password)
  .then( () => {
    console.log('password updated')
  }
  .catch(error => {
    console.log(error.code, error.message)
  })

NOTE: I have not confirmed your version of the code to update the password, but have used the confirmPasswordReset.

Sign up to request clarification or add additional context in comments.

2 Comments

My code example was to correct the assumptions of your calls, but as I noted you may need to use confirmPasswordReset after a return of the code from the sendPasswordResetEmail
Thank you. The second way, confirmPasswordReset, is working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.