在Firebase上更新密码时,我不想离开我的应用程序 [英] I don't want to get out of my application when update the password on firebase

查看:49
本文介绍了在Firebase上更新密码时,我不想离开我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在后端通过Iam编程,当我在Firebase上更新密码时退出我的应用程序

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

我也应该从后端更改密码吗?,实际上我正在使用Firebase管理员

i should change the password from backend as well?, actually i am using firebase admin

我必须从后端进行更改,还是必须从前端进行足够的更改?

推荐答案

我已经使用Firebase身份验证在代码中实现了密码更改功能.
根据Firebase文档,您需要在更改密码之前重新验证当前用户.
因此,请尝试实现该功能,因为在我的情况下,更改密码后它不会使我退出应用程序.
在这里,您可以通过提供电子邮件和当前密码来获取当前用户密码.

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
 });

请参阅此作为参考-
https://firebase.google.com/docs/auth/网络/管理用户#re-authenticate_a_user https://firebase.google.com/docs/auth/web/manage-users#set_a_users_password

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

这篇关于在Firebase上更新密码时,我不想离开我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆