0

In my Firebase web app, I offer 3 different authentication methods – phone, email/password, and Google.

When new users go through the FirebaseUI sign-in flow, sometimes they don't remember which method they signed up with originally and use a different method (which creates a new user). For example, they created an account originally using their phone number, but when they return later (unauthenticated, perhaps on a new device), they see "Sign in with Google" and try that option – which creates a brand new user/account.

They are then confused why their account state is blank/new.

Is there a way to define a sign-in flow as such, so that if a user does not exist, it should not create a duplicate account (or at least offer an option to link to an existing user)?

I'm using the FirebaseUI for simplicity and hoping there's a flag or something I can set in the config that will achieve this.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
ehed
  • 804
  • 1
  • 8
  • 18

1 Answers1

1

For example, they created an account originally using their phone number, but when they return later (unauthenticated, perhaps on a new device), they see "Sign in with Google" and try that option – which creates a brand new user/account.

That's normal behavior since you don't have any information that it is the same user. To solve this, you should collect the email address of the user first time he/she signs up with the phone number. In this way, you can check the second time, whether the user has already an account in your app by searching for the existence of the email, as explained in my answers from the following posts. That's for the Realtime Database:

And that's for Firestore:

Is there a way to define a sign-in flow as such, so that if a user does not exist, it should not create a duplicate account (or at least offer an option to link to an existing user)?

Yes, by getting specific data to recognize the user. You either get the email address, as explained above or you get the phone number if it tries to sign in the first time with Google.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193