changePassword() method in Firebase version 3

19,482

Solution 1

Since Firebase v3.0, changePassword method is not available anymore. If you need to reset your user's password you can use custom email action handlers : https://firebase.google.com/docs/auth/custom-email-handler

The following user management actions require the user to complete the action using an email action handler: Resetting passwords

I recommend you read the documentation and you'll get started really quick to reset your user's password.

EDIT : If you don't need to reset the password but just update it, you can use the updatePassword method.

let user = firebase.auth().currentUser;
let newPassword = getASecureRandomPassword();

user.updatePassword(newPassword).then(() => {
  // Update successful.
}, (error) => {
  // An error happened.
});

Important: To set a user's password, the user must have signed in recently. See Re-authenticate a user.

More informations here : https://firebase.google.com/docs/auth/web/manage-users#set_a_users_password

Hope this helps !

Solution 2

firebase.auth()
        .signInWithEmailAndPassword('email', 'oldPassword')
        .then(function(user) {

            firebase.auth().currentUser.updatePassword('newPassword').then(function(){

                //Do something

            }).catch(function(err){
                //Do something
            });

        }).catch(function(err){
            //Do something
        });
Share:
19,482

Related videos on Youtube

yogieputra
Author by

yogieputra

Updated on September 15, 2022

Comments

  • yogieputra
    yogieputra over 1 year

    I'm using firebase ver 3.2.1 in my React Native iOS project. I read the log from version 2.4.2 here, there is a method named changePassword() which can be used to change user's password.

    But when I look docs for Firebase ver 3.2.1 I can't find any method named changePassword(). So I'm wondering, is changePassword() method can not be used in Firebase version 3 anymore?

    Thanks.

  • Leo Galindo
    Leo Galindo over 4 years
    This works like a charm! just copy and paste and see the magic :D
  • prog
    prog almost 4 years
    this is great thanks i changed the function to es6 arrow function but other then that awesome!