【问题标题】:How to reauthorize a user in Firebase?如何在 Firebase 中重新授权用户?
【发布时间】:2021-08-24 03:29:19
【问题描述】:

环境

  • Firebase JavaScript SDK v8

问题

如何使用密码重新授权已登录的用户?我想做的如下:

const password = "some-password"
firebase.reAuthorizeUser(password)
  .then(() => console.log("ok"))
  .catch(() => console.log("ng"))

提前谢谢你。

【问题讨论】:

    标签: javascript firebase firebase-authentication


    【解决方案1】:

    您正在寻找reauthenticateWithCredential 方法。

    const user = firebase.auth().currentUser;
    
    // TODO(you): prompt the user to re-provide their sign-in credentials
    const credential = promptForCredentials();
    
    user.reauthenticateWithCredential(credential).then(() => {
      // User re-authenticated.
    }).catch((error) => {
      // An error ocurred
      // ...
    });
    

    在文档中结帐reauthenticate a user

    【讨论】:

    • 感谢您的温柔回答!很有帮助!
    【解决方案2】:

    const credential = promptForCredentials();

    这给了我错误

    找不到变量:promptForCredentials。

    【讨论】:

    • promptForCredentials() 不是预定义函数。您必须编写自己的代码才能获得UserCredential
    猜你喜欢
    • 2020-04-12
    • 1970-01-01
    • 2018-06-07
    • 2013-02-23
    • 2019-09-27
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    相关资源
    最近更新 更多