Home > Software design >  Detect if user alread has signed in with another provider
Detect if user alread has signed in with another provider

Time:04-04

I have an app where you can either sign in via Apple Sign In, or Google Sign In. Assuming I have had an Android where I have signed in with Google. Then I change to iPhone and want to use Apple Sign In.

Currently if I sign in with Apple, I will get a different uid from FirebaseUser compared to what I get when I sign in with Google.

Is there a way I can detect that there already is a user on Firebase and get that uid instead?

I am using Flutter and have read about linking, but that was not exactly what I wanted.

CodePudding user response:

You can link multiple auth providers to single account but that would still require user to login with their existing user credentials first. The domain of Google Account (e.g. @gmail.com) and Apple ID (e.g. @icloud.com) might be different so it's unlikely for Firebase to treat them as single account like it does for email-password and Google Accounts.

CodePudding user response:

The typical flow to allow the user to sign in with multiple providers is:

  1. Ask for their email address, which is their primary identifier within Firebase.
  2. Call fetchSignInMethodsForEmail to check what provider(s) are associated with that email address.
  3. If any: show a screen where the user can choose from the associated providers to complete the sign-in.
  4. If none: show a screen allowing the user to choose any of the providers you want to allow.

As Dharmaraj said, you can in step 4 allow linking the new provider with an existing account, but you may have to ask the user for more information than just their email address to be able to make that mapping.

  • Related