【问题标题】:Firebase Authentication - Linking other auth providersFirebase 身份验证 - 链接其他身份验证提供程序
【发布时间】:2018-10-31 19:33:21
【问题描述】:

我正在使用 web 中的 firebase 身份验证,但遇到了问题。我使用谷歌登录了一个用户,现在我还希望用户创建一个密码,以便他可以使用电子邮件和密码登录。 所以基本上我想把它们都链接起来。

我尝试了 firebase.auth.createUserWithEmailAndPassword(userEmail, newpassword) 但它抛出一个错误“email-already-in-use”这是正确的,因为我先用谷歌登录。

有什么方法可以链接这些吗?

【问题讨论】:

    标签: javascript firebase firebase-authentication


    【解决方案1】:

    这是一个如何将电子邮件/密码凭据链接到现有用户的示例(请注意,您也可以只使用用户 updatePassword

    // Email/Password credential. Similar logic can be used for linking
    // other credentials.
    var cred = firebase.auth.EmailAuthProvider.credential(
        firebase.auth().currentUser.email, 'password');
    firebase.auth().currentUser.linkWithCredential(cred)
      .then(function() {
        // Credential successfully linked.
      })
      .catch(function(error) {
        // Some error occurred.
      });
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 2023-03-15
      • 2017-12-25
      • 1970-01-01
      • 2018-03-09
      • 2020-09-28
      • 2020-08-21
      • 2015-08-24
      • 2021-02-28
      • 2021-04-02
      相关资源
      最近更新 更多