问题
Iam programming on backend side, when i update the password on firebase my app logout
admin.auth().getUserByEmail(email).then(user => {
const { uid } = user
admin.auth().updateUser(uid,{
password,
})
I don't want to get out of my application. when I edit my password, I think the TOKENS are destroyed and my application rejects me, my user goes out of the application
I just want to update my password I don't want to quit the application
i should change the password from backend as well?, actually i am using firebase admin
I must change from my backend or enough from the frontend?
回答1:
I have implemented the password change feature in my code using firebase authentication.
According to firebase docs, you need to reauthenticate the current user before changing the password.
So try implementing that, because in my case it does not log me out of my application after changing password.
Here you can get the current user password by providing email and current password.
var user = firebase.auth().currentUser;
var credential = firebase.auth.EmailAuthProvider.credential(
email,
current_password
);
After that, you can reauthenticate the user and update the password as I am doing here.
user.reauthenticateWithCredential(credential).then( data => {
// User re-authenticated.
user.updatePassword(newpassword)
.then(() => {
//Password successfully updated
})
.catch((error) => {
//Failed to update password
});
}).catch((error) => {
//An error happened.
//Failed to reauthenticate user
});
See this for reference -
https://firebase.google.com/docs/auth/web/manage-users#re-authenticate_a_user
https://firebase.google.com/docs/auth/web/manage-users#set_a_users_password
来源:https://stackoverflow.com/questions/62845126/i-dont-want-to-get-out-of-my-application-when-update-the-password-on-firebase