【问题标题】:Flutter Change password of firebase user is not workingFlutter更改firebase用户的密码不起作用
【发布时间】:2020-08-21 09:01:26
【问题描述】:

我正在尝试为 firebase 用户更改密码。

handleChangePassword(BuildContext parentContext) {
    return showDialog(
        context: parentContext,
        builder: (_) {
          return ChangePasswordPopUp(
            currentEmail: widget.email,
            auth: widget.auth,
            newPassword: (val) async {
              await widget.auth.changePassword(val);
            },
          );
        });
  }

用户在 ChangePasswordPopUpValueChanged newPassword 中重新认证,我正在调用 changePassword

Future<void> changePassword(String password) async {
    FirebaseUser user = await _firebaseAuth.currentUser();
    print(password);
    user.updatePassword(password).then((_){
      print("Succesfull changed password");
    }).catchError((error){
      print("Password can't be changed" + error.toString());
    });
  }

它会打印选择的新密码和“成功更改密码”,所以一切都应该没问题,但是当我尝试注销并再次登录时,它是旧密码而不是新密码。

有什么建议吗?

【问题讨论】:

标签: firebase flutter firebase-authentication


【解决方案1】:
void _changePassword(String password) async{
   //Create an instance of the current user. 
    FirebaseUser user = await FirebaseAuth.instance.currentUser();

    //Pass in the password to updatePassword.
    user.updatePassword(password).then((_){
      print("Your password changed Succesfully ");
    }).catchError((err){
      print("You can't change the Password" + err.toString());
      //This might happen, when the wrong password is in, the user isn't found, or if the user hasn't logged in recently.
    });
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 2015-08-06
    • 2016-12-11
    • 1970-01-01
    • 2021-10-29
    相关资源
    最近更新 更多