![](/img/trans.png)
[英]How to handle Firebase Auth account-exists-with-different-credential Errors
[英]Firebase Auth with Facebook fails if the account already exists and is associated with a Google Auth
我實現了一個包含 2 個按鈕的簡單應用程序:1 個通過 Google 登錄,另一個通過 Facebook 登錄。
兩種身份驗證方法都可以單獨使用,但在以下情況下事情會變得更加復雜:
下面是錯誤代碼auth/account-exists-with-different-credential
已經在 stackoverflow Firebase JS API auth - account-exists-with-different-credential中引用過
問題是我得到的error
object 在我構建的小應用程序中不包含credential
屬性名稱(順便說一句,也不包含email
屬性名稱)。
應用程序中 loginWithFacebook.js 的摘錄
export async function loginWithFacebook() {
signInWithPopup(auth, new FacebookAuthProvider())
.then((result) => {
const user = result.user;
console.log(user);
})
.catch(function (error) {
if (error.code === 'auth/account-exists-with-different-credential') {
console.log(error.credential); // undefined
console.log(error.email); // undefined
}
});
}
我有同樣的問題,我能夠通過查看返回錯誤的customData
屬性來克服它。 可能這種不同的行為與 Firebase 的特定版本有關。我的是 firebase@9.6.9。
所以,試試看這是否有效:
export async function loginWithFacebook() {
signInWithPopup(auth, new FacebookAuthProvider())
.then((result) => {
const user = result.user;
console.log(user);
})
.catch(function (error) {
if (error.code === 'auth/account-exists-with-different-credential') {
console.log(FacebookAuthProvider.credentialFromError(error));
console.log(error.customData.email);
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.