【问题标题】:Reauthenticating Firebase user with Google Provider in React在 React 中使用 Google Provider 重新验证 Firebase 用户
【发布时间】:2019-02-14 09:38:12
【问题描述】:

我正在为我的网络项目使用 firebase,并希望允许用户删除他们的帐户,根据 Firebase,这需要 reauth。我在让他们的 user.reauthenticateAndRetrieveDataWithCredential 工作时遇到了很多麻烦。

具体来说,我不知道如何生成AuthCredential 以使用GoogleAuthProvider.credential() method 传递给它,因为我不知道如何获取用户的ID 令牌或访问令牌。

我尝试了user.getIdToken() (here),这给了我一个错误,即凭据不是由 Google 颁发的。

要求用户通过弹出窗口再次登录,然后使用res.credential accessToken 或 idToken 有效,但随后允许他们在当时登录到其他用户,这不是我想要的。

关于如何从当前登录的用户那里获取有效的 idToken 进行重新认证的任何提示?

谢谢!

【问题讨论】:

    标签: firebase firebase-authentication


    【解决方案1】:

    只需使用reauthenticateWithPopup/reauthenticateWithRedirect

    firebase.auth().currentUser.reauthenticateWithPopup(new firebase.auth.GoogleAuthProvider())
      .then(function(userCredential) {
        // You can now delete the user:
        return firebase.auth().currentUser.delete();
      })
      .catch(function(error) {
        // Credential mismatch or some other error.
      });
    

    【讨论】:

    猜你喜欢
    • 2017-04-15
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 2021-02-08
    • 2022-08-19
    • 2018-03-28
    相关资源
    最近更新 更多