Firebase JS API auth - account-exists-with-different-credential [英] Firebase JS API auth - account-exists-with-different-credential

查看:143
本文介绍了Firebase JS API auth - account-exists-with-different-credential的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在尝试解决此问题时遇到了实际问题,因此希望获得一些Firebase帮助/已解决相同问题的帮助。

We're having real problems trying to resolve this and so hoping for some Firebase assistance / those that have solved the same problem.

该应用是React Native( 0.43.2)并使用Firebase JS API(最新版)

The app is React Native (0.43.2) and using Firebase JS API (latest)

我们提供Facebook和Google身份验证。工作正常。

We provide Facebook and Google auth. Works fine.

但是,如果是用户:


  1. 使用Facebook登录(没关系)

  2. 稍后,使用Google登录(也没关系)

  3. 稍后,尝试使用Facebook登录 - BOOM!不太好,Firebase会返回此错误:

auth / account-exists-with-different-credential

通过阅读文档和SO上的一些帖子,我们认为以下内容是正确的,但显然不是因为我们收到相同的身份验证错误。

From reading docs and a few posts on SO, we thought the following was correct but clearly not as we're getting the same auth error back.

...error returned by Firebase auth after trying Facebook login...

const email = error.email;
const pendingCred = error.credential;

firebase.auth().fetchProvidersForEmail(email)
.then(providers => {
   //providers returns this array -> ["google.com"]
   firebase.auth().signInWithCredential(pendingCred)
   .then(result => {
       result.user.link(pendingCred)
   })
   .catch(error => log(error))

对signInWithCredential的调用抛出相同的错误 auth / account-exists-with-different-credential

The call to signInWithCredential is throwing the same error auth/account-exists-with-different-credential.

任何人都可以帮助指出我们做错了什么实施?非常感谢。

Can anyone help point out what we are doing wrong with this implementation? Greatly appreciated.

推荐答案

Firebase为所有电子邮件强制执行相同的帐户。正如您已经拥有Google一样对于同一封电子邮件,您需要将该Facebook帐户与Google帐户相关联,以便用户可以访问相同的数据,并且下次可以使用Google或Facebook登录同一帐户。

What is happening is that Firebase enforces a same account for all emails. As you already have a Google account for the same email, you need to link that Facebook account to the Google account so the user can access the same data and next time be able to sign in to the same account with either Google or Facebook.

你的sn中的问题ippet是您签署并链接相同的凭证。修改如下。
当您收到错误'auth / account-exists-with-different-credential'时,
错误将包含error.email和error.credential(Facebook OAuth凭证)。您需要先查找error.email以获取现有提供程序。

The issue in your snippet is that you are signing and linking with the same credential. Modify as follows. When you get the error 'auth/account-exists-with-different-credential', the error will contain error.email and error.credential (Facebook OAuth credential). You need to first lookup the error.email to get the existing provider.

firebase.auth().fetchProvidersForEmail(error.email)
  .then(providers => {
    //providers returns this array -> ["google.com"]
    // You need to sign in the user to that google account
    // with the same email.
    // In a browser you can call:
    // var provider = new firebase.auth.GoogleAuthProvider();
    // provider.setCustomParameters({login_hint: error.email});
    // firebase.auth().signInWithPopup(provider)
    // If you have your own mechanism to get that token, you get it
    // for that Google email user and sign in
    firebase.auth().signInWithCredential(googleCred)
      .then(user => {
        // You can now link the pending credential from the first
        // error.
        user.linkWithCredential(error.credential)
      })
      .catch(error => log(error))

这篇关于Firebase JS API auth - account-exists-with-different-credential的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆