[英]Is it safe to allow multiple Firebase accounts with the same email address?
[英]Firebase Allowing Multiple Accounts from Same Email Address
在 Firebase 控制台中,我專門將其設置為僅允許“每個 email 地址一個帳戶”。 這可以在“高級”下的登錄方法選項卡上找到。
我有一個使用 Google 登錄方法創建的帳戶,其地址類似於“me@gmail.com”。 如果我然后選擇使用也使用“me@gmail.com”的帳戶通過 Facebook 登錄,則 Firebase 允許它,但用戶實體中的 email 地址是 null。
Firebase 文檔指出:
如果您不允許多個帳戶使用相同的 email 地址,則用戶無法創建使用地址為 email 的 Google 帳戶登錄的新帳戶 ex@gmail.com 如果已經有一個帳戶使用 email 地址登錄ex@gmail.com 和密碼。
如果您嘗試直接使用用戶名/密碼創建 Firebase 登錄,而不是從兩個提供商(如 Facebook 和 Google)創建帳戶,這是否才算數? 我的印象是,如果它找到重復的 email 地址,它應該拒絕注冊/登錄。 我確實意識到引用狀態“和密碼”讓我感到奇怪。
第1步:轉到Firebase控制台>身份驗證>登錄方法。 選中防止使用單個電子郵件ID創建多個帳戶的選項。
步驟2:以下文檔說明如何使用自定義方法將多個提供程序連接到單個帳戶。
擴展Kathir的答案,Firebase文檔確實提供了解決方案 。
以下是從文檔中復制的代碼段。
// Step 1.
// User tries to sign in to Google.
auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()).catch(function(error) {
// An error happened.
if (error.code === 'auth/account-exists-with-different-credential') {
// Step 2.
// User's email already exists.
// The pending Google credential.
var pendingCred = error.credential;
// The provider account's email address.
var email = error.email;
// Get sign-in methods for this email.
auth.fetchSignInMethodsForEmail(email).then(function(methods) {
// Step 3.
// If the user has several sign-in methods,
// the first method in the list will be the "recommended" method to use.
if (methods[0] === 'password') {
// Asks the user their password.
// In real scenario, you should handle this asynchronously.
var password = promptUserForPassword(); // TODO: implement promptUserForPassword.
auth.signInWithEmailAndPassword(email, password).then(function(user) {
// Step 4a.
return user.linkWithCredential(pendingCred);
}).then(function() {
// Google account successfully linked to the existing Firebase user.
goToApp();
});
return;
}
// All the other cases are external providers.
// Construct provider object for that provider.
// TODO: implement getProviderForProviderId.
var provider = getProviderForProviderId(methods[0]);
// At this point, you should let the user know that he already has an account
// but with a different provider, and let him validate the fact he wants to
// sign in with this provider.
// Sign in to provider. Note: browsers usually block popup triggered asynchronously,
// so in real scenario you should ask the user to click on a "continue" button
// that will trigger the signInWithPopup.
auth.signInWithPopup(provider).then(function(result) {
// Remember that the user may have signed in with an account that has a different email
// address than the first one. This can happen as Firebase doesn't control the provider's
// sign in flow and the user is free to login using whichever account he owns.
// Step 4b.
// Link to Google credential.
// As we have access to the pending credential, we can directly call the link method.
result.user.linkAndRetrieveDataWithCredential(pendingCred).then(function(usercred) {
// Google account successfully linked to the existing Firebase user.
goToApp();
});
});
});
}
});
@AndroidBeginner 的回答幫助我解決了這個問題,但是,“帳戶 Email 設置”選項不再位於身份驗證 --> 登錄方法下,我在身份驗證 --> 設置下找到它,它是頂部“用戶帳戶”的第一個選項鏈接”。
單擊“為每個身份提供者創建多個帳戶”確實解決了我在 chrome 控制台中的錯誤,我可以使用 chrome 和 Facebook 在我的應用程序中登錄/注冊,但現在我確實有多個用戶使用相同的 email...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.