Android Firebase Linking Multiple Account Providers With Matching Email
Solution 1:
To link accounts, there should be an existing session. For example lets say that a new user creates an account using Google as the auth provider.
In summary, to do this you will need to:
- Use GIDSignIn to authenticate the user with Google.
- Then Google returns an Id Token (if everything goes well).
- You will use the token to create a GoogleAuthProvider credential object.
- And then you use this credential to authenticate in Firebase calling signInWithCredential.
The process is similar with other auth providers like Facebook. In order to link the account with Facebook, you will need to do the first three steps mentioned above (related to Facebook auth) but instead of "signInWithCredential" you will need to call "linkWithCredential". If everything goes well, now the user will be able to authenticate to the same account with Google or Facebook.
If you call "signInWithCredential", you will create a new account that uses Facebook as auth provider. So a user instead of being able to access to a single account with two(or more) auth providers, that user will have two separate accounts for each auth provider. This is why the documentation says that you should skip calling FirebaseAuth.signInWith methods.
Regarding your question about merging, the documentation mentions: "The call to linkWithCredential will fail if the credentials are already linked to another user account". This means that a user has already an account with the auth provider. If you want the user to access the information from both accounts, you will need to create the logic to merge the information from one account to the other.
Post a Comment for "Android Firebase Linking Multiple Account Providers With Matching Email"