我们在尝试解决这个问题时遇到了真正的问题,所以希望得到一些 Firebase 帮助/那些已经解决了同样问题的人。
该应用程序是 React Native (0.43.2) 并使用 Firebase JS API(最新)
我们提供 Facebook 和 Google 身份验证。工作正常。
但是,如果用户:
- 使用 Facebook 登录(可以)
- 稍后,用谷歌登录(也可以)
- 稍后,尝试使用 Facebook 登录 - BOOM!不太好,Firebase 返回此错误:
auth/account-exists-with-different-credential
通过阅读文档和关于 SO 的一些帖子,我们认为以下内容是正确的,但显然不是,因为我们得到了相同的身份验证错误。
...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
。
任何人都可以帮助指出我们在这个实现中做错了什么吗?非常感激。