How can I solve create account problem with different providers?

Viewed 73

I have a sign in with Google:example@gmail.com

then create an account with the same email:example@gmail.com

There is a problem with two different providers

  1. Sign in with Google (same Gmail)
  2. Sign in with Email (same Gmail)

How Can I handle these two (When I delete the google sign-in account from Firebase Console. I can create an account with that email) Otherwise I can't create an account with that email and also can't sign in.

I learning Firebase Auth with https://github.com/gladly-team/next-firebase-auth

1 Answers

If you first sign in with Google using "example@gmail.com", it means a user will be created using this particular email address. If you try to sign in with any other provider or with an email and password using the same email address, you'll get an error message that says that the user already exists. And it makes sense since you have already used that email for a user before.

There are two ways in which you can solve this problem. When you get such an error, you can check the provider used to create the account, and notify the user to use it. For example, if the user signs in with Google and tries to authenticate with email and password right after that, display a message to the user in which you should say that the user already exists, and should use the authentication provider which was selected to create the account in the first place, in this case, Google.

The second option would be to allow the user to have multiple accounts using the same email address with different authentication providers. This option can be enabled directly in the Firebase Console, in the Authentication section.

So it's up to you to decide which option works better for your project.

Related