Raghav Parsai
Raghav Parsai

Reputation: 1

Link multiple Authentication provider | Firebase Authentication

I'm stuck in a login/registration flow with Firebase. I have a simple use case where users can register/login with email-password and login with Google. If a user is registered with email-pass and tries to log in with google with the same email id, I want to link both providers with one account. I know this can be done once the user is logged in, but I want to do it when the user is trying to log in via google, and some prompt will come up as "you already have an account, please enter your password to connect".

I have tried the scenario where the user is logged in with an email pass and trying to connect their google account.

Upvotes: 0

Views: 195

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 139039

If a user is registered with email-pass and tries to log in with Google with the same email id, I want to link both providers with one account.

That is happening by default. If a user signs in using email and password and later using Google provider, their account sign-in method is automatically converted to Google. Why? Because according to the official documentation, Google is considered a trusted provider:

  • Trusted providers:

Google (for @gmail.com addresses)

And:

Untrusted providers:

Email / Password without email verification

In some situations, Firebase will automatically link accounts when a user signs in with different providers using the same email address.

That's because by default a user can have only one account per email address. This is done to prevent users from creating multiple accounts using the same email address with different authentication providers. However, this can be changed in the Firebase console, in the "Sign-in method" tab, inside the Authentication section.

So remember, Firebase Authentication has the concept of a preferred provider for certain email addresses, and unfortunately, there is no way to change this behavior, at least at the time I'm answering this question.

Upvotes: 1

Related Questions