【问题标题】:How to change the email and the password of the user in dart firebase如何在dart firebase中更改用户的电子邮件和密码
【发布时间】:2021-12-20 02:40:03
【问题描述】:

我想在 Firestore 和身份验证中更改用户的电子邮件和密码,以便用户可以使用更新后的电子邮件和密码登录

【问题讨论】:

    标签: firebase dart firebase-authentication


    【解决方案1】:

    我想更改用户的邮箱和密码

    我了解您不希望这些更改由用户自己完成,而是由其他用户(如管理员)完成。

    在这种情况下,您不能使用 Dart firebase_auth library,因为 updateEmail()updatePassword() 方法必须由用户自己调用


    另一方面,使用Firebase Admin SDK,您可以修改现有用户的数据(无需以该用户身份进行身份验证)。要使用 Admin SDK,您需要在特权环境中执行此操作,例如您管理的服务器或通过 Cloud Functions。

    以下 Node.js 代码可用于Cloud Function

    const uid =  .... // Specify the user's uid
    getAuth()
      .updateUser(uid, {
        email: 'modifiedUser@example.com',
        password: 'newPassword',
      })
      .then((userRecord) => {
        // See the UserRecord reference doc for the contents of userRecord.
        console.log('Successfully updated user', userRecord.toJSON());
      })
      .catch((error) => {
        console.log('Error updating user:', error);
      });
    

    【讨论】:

    • 谢谢您,我将在管理员方面使用您的解决方案。但是,我正在尝试更新用户端的电子邮件和密码,但使用 updateEmail 和 updatePassword 对我不起作用
    • 就像我在anwser中写的,updateEmail()updatePassword()方法必须由用户自己调用。
    • @Nouf:如果您尝试过 API 但无法使其正常工作,请编辑您的问题(下方有一个链接)以显示 minimal, complete/standalone code that reproduces where you got stuck
    猜你喜欢
    • 2016-06-27
    • 2014-05-24
    • 1970-01-01
    • 2019-12-06
    • 1970-01-01
    • 2019-10-20
    • 2018-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多