【问题标题】:How do I modify my delete account function to work for Google accounts?如何修改我的删除帐户功能以适用于 Google 帐户?
【发布时间】:2021-04-19 13:58:44
【问题描述】:

我的网络应用使用 Firebase 身份验证来获取电子邮件和密码,并使用 Google 登录。 我有这个旨在删除用户帐户的功能:

const deleteUserAccount = () => {
    firebase.auth().currentUser.reauthenticateWithCredential(firebase.auth.EmailAuthProvider.credential(currentUser.email, reEnterPassword)).then(() => {
        firebase.firestore().collection("users").doc(firebase.auth().currentUser.uid).delete().then(() => {
            firebase.auth().currentUser.delete().then(() => {

            }).catch((error) => {
                console.log(error)
            })
        }).catch((error) => {
            console.log(error)
        })
      }).catch((error) => {
            console.log(error)
        })
}

此代码仅适用于使用电子邮件和密码登录的用户,并且尝试使用使用 Google 登录的帐户运行它会返回此错误:

代码:“验证/错误密码” message: "密码无效或用户没有密码。"

我做错了什么以及如何修改它以适应两种身份验证类型?

【问题讨论】:

    标签: javascript firebase web-applications firebase-authentication


    【解决方案1】:

    如果您使用 Google(或任何其他社交服务提供商)登录,则 Firebase 身份验证用户帐户没有与之关联的密码。因此,要再次登录该帐户,用户必须使用与以前相同的 Google 凭据登录。

    如果您希望允许用户使用密码登录该帐户,您可以通过lining email address and password credentials to the user account 设置链接的电子邮件+密码帐户。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 2018-07-31
      • 2012-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多