Firebase允许来自同一电子邮件地址的多个帐户

Firebase允许来自同一电子邮件地址的多个帐户,firebase,firebase-authentication,Firebase,Firebase Authentication,在Firebase控制台中,我专门将其设置为“每个电子邮件地址只允许一个帐户”。这可以在“高级”下的“登录方法”选项卡上找到 我有一个使用Google登录方法创建的帐户,其地址如下“me@gmail.com". 如果我选择通过Facebook登录,使用的帐户也使用“me@gmail.com,Firebase允许它,但用户实体中的电子邮件地址为空除外 Firebase文档说明: 如果不允许多个帐户使用相同的电子邮件地址,则 用户无法创建使用Google帐户登录的新帐户 用电子邮件地址ex@gma

在Firebase控制台中,我专门将其设置为“每个电子邮件地址只允许一个帐户”。这可以在“高级”下的“登录方法”选项卡上找到

我有一个使用Google登录方法创建的帐户,其地址如下“me@gmail.com". 如果我选择通过Facebook登录,使用的帐户也使用“me@gmail.com,Firebase允许它,但用户实体中的电子邮件地址为空除外

Firebase文档说明:

如果不允许多个帐户使用相同的电子邮件地址,则 用户无法创建使用Google帐户登录的新帐户 用电子邮件地址ex@gmail.com如果已经有账户 使用电子邮件地址登录的ex@gmail.com和密码


仅当您试图使用用户名/密码直接创建Firebase登录,而不是从Facebook和Google这两个提供商创建帐户时,这才算有效吗?我的印象是,如果发现重复的电子邮件地址,它应该拒绝注册/登录。我确实意识到引号中有“和密码”,这让我很好奇。

转到Firebase控制台

在身份验证->登录方法中

向下滚动到高级部分 单击更改,然后保存


步骤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();
        });
      });
    });
  }
});

我不明白这是怎么解决问题的。我不想允许多个帐户使用相同的电子邮件地址。这就是为什么我选择用顶部按钮来阻止它。根据我上面的描述,我正在寻找Firebase没有做的事情。更糟糕的是,我启用了allow流只是为了看看它会做什么。实际上,它的作用与“阻止流动”完全相同。它创建一个没有电子邮件地址的帐户,并且UID与具有相同电子邮件地址的其他帐户不同。所以这两个流似乎都没有达到预期的效果。您是如何解决这个问题的?我也有类似的问题。我在考虑允许每封电子邮件有多个帐户,并在Firestore数据库中将用户的电子邮件用作我的“用户ID”。因为如果我的用户使用相同的电子邮件和不同的登录方法创建多个帐户,他们将拥有多个UID。电子邮件将是两个帐户之间唯一的共同点。因此,我倾向于使用电子邮件作为我的“主键”。@AndroidBeginner您会使用什么作为识别用户的UID?他们将在使用相同电子邮件和不同登录方法创建的每个帐户上使用不同的UID。例如:UID1表示电子邮件/密码,UID2表示电子邮件/谷歌,UID3表示电子邮件/facebook,UID4表示电子邮件/推特等。您如何处理此问题?能否提供报价来源。我在firebase中还没有在线找到关于此的文档。你有链接吗?@j2emanue这是链接:@C6Silver你是怎么解决的?@cbdev420-每次注册我都会在Firebase上创建帐户之前检查电子邮件是否存在。@C6Silver你提到的这封电子邮件检查在你的Firebase数据库中?那么您允许Firebase Auth上的每封电子邮件有多个帐户?您是否将电子邮件用作数据库(Firestore/RealTimeDB)中的“用户ID”?谢谢