How to verify users current password?

后端 未结 1 1585
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 00:44

So, maybe I missed this somewhere in the docs but I couldn\'t find anything of the sort.

I wan\'t my users to have to type in their current password to be able to creat

1条回答
  •  伪装坚强ぢ
    2021-02-19 01:07

    UPDATE: (Use - reauthenticateWithCredential)

    var user = firebaseApp.auth().currentUser;
    var credential = firebase.auth.EmailAuthProvider.credential(
      firebase.auth().currentUser.email,
      providedPassword
    );
    
    // Prompt the user to re-provide their sign-in credentials
    
    user.reauthenticateWithCredential(credential).then(function() {
      // User re-authenticated.
    }).catch(function(error) {
      // An error happened.
    });
    

    PREVIOUS VERSION

    you can use reauthenticate API to do so. I am assuming you want to verify a current user's password before allowing the user to update it. So in web you do something like the following:

    reauthenticateAndRetrieveDataWithCredential- DEPRECATED

    firebase.auth().currentUser.reauthenticateAndRetrieveDataWithCredential(
      firebase.auth.EmailAuthProvider.credential(
        firebase.auth().currentUser.email, 
        providedPassword
      )
    );
    

    If this succeeds, then you can call

    firebase.auth().currentUser.updatePassword(newPassword);
    

    0 讨论(0)
提交回复
热议问题