Muli
Muli

Reputation: 214

Password reset on Firebase with VueJs

I want to reset the password with Vuejs. I managed to send the reset password link with my custom url, and when the users click on it it redirects to a custom form. Password reset url is:

http://localhost:8080/passwordreset?mode=resetPassword&oobCode=viIqct7-jvuNnZxMEgyyRualxpX5CmZ3_EJrCQi-C88AAAFeuLXmWg&apiKey=AIzaSyBaCCvq-ZEfQmdrL7fmElXDjZF_J-tku2I

<input type="password" v-model="passwordNew" class="" placeholder="New password">

<input type="password" v-model="passwordConfirm"class=""placeholder="Confirm Password">

<button class="btn" v-on:click="resetPassword">Reset Password</button>

My password reset file is a component, under my <script> i have:

import firebase from 'firebase'
export default {

    data: function() {
        return {
            passwordNew: '',
            passwordConfirm: '',
        }
    },
    methods: {
        resetPassword: function() {
            var newPassword = this.passwordNew

            var user = firebase.auth().currentUser;
            console.log ("  User:  "+ user );

            user.updatePassword(newPassword).then(function() {
              // Update successful.
              alert("Reset Password successful")
            }).catch(function(error) {
              // An error happened.
            });

        },
        checkPasswords: function () {

        }
    }

}

All I get when the user sets the new password is on console that user is null, see image below:

enter image description here

Upvotes: 2

Views: 4662

Answers (1)

bojeil
bojeil

Reputation: 30798

You are using this incorrectly. When you are sending a reset password email, it means the user is not logged in. When you update a password, the user is already logged in. In your case, you need to call auth.confirmPasswordReset(code, newPass). For more on this API, check: https://firebase.google.com/docs/reference/js/firebase.auth.Auth#confirmPasswordReset

For more on building your own password reset landing page, check: https://firebase.google.com/docs/auth/custom-email-handler

Upvotes: 1

Related Questions