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.
Solution 1: Dharmaraj
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. code>@gmail.com</code) and Apple ID (e.g. code>@icloud.com</code) might be different so it's unlikely for Firebase to treat them as single account like it does for email-password and Google Accounts.
Solution 2: Frank van Puffelen
The typical flow to allow the user to sign in with multiple providers is:
- Ask for their email address, which is their primary identifier within Firebase.
fetchSignInMethodsForEmailto check what provider(s) are associated with that email address.
- If any: show a screen where the user can choose from the associated providers to complete the sign-in.
- 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.