Search code examples
androidfirebasefirebase-authenticationfirebaseui

Option of create multiple accounts for each identity provider not working as expected in Firebase Authentication


As you can see in the image below, I enabled the second option (Create multiple accounts for each identity provider)

enter image description here

Now this email m6454611@gmail.com is already in Firebase Authentication and I already logged in using Google provider.

I want to create a new account with the same email in the above but with the email provider but it tells me email account registration unsuccessful. It will work without any problems if I delete the email that signed in via Google provider.

enter image description here

I expected it will create the same email without any problems because it is a different provider

Did I misunderstand anything?


Solution

  • For linking multiple providers to the same account, you don't use the create user method there is a link method for it:

    https://firebase.google.com/docs/auth/web/account-linking

    import { getAuth, linkWithCredential } from "firebase/auth";
    
    const auth = getAuth();
    linkWithCredential(auth.currentUser, credential)
      .then((usercred) => {
        const user = usercred.user;
        console.log("Account linking success", user);
      }).catch((error) => {
        console.log("Account linking error", error);
      });
    

    Basically, the behavior is that the account is already created, and already logged on, and then you can link their existing account with a new provider.