Skip to content
Advertisement

What’s the difference with linkWithCredential and linkWithPopup

I read the Convert an anonymous account to a permanent account and see that using the:

auth.currentUser.linkWithCredential(credential)

will merge the anonymous and e.g., Google, Facebook etc.. credential

Then I read Link Multiple Auth Providers to an Account Using JavaScript will do the same using the:

auth.currentUser.linkWithPopup(provider)

What is the difference and which should I use if my SPA Reactjs app require anonymous sign and later if user want to sign in he can do that with Google, Facebook..

I run some test and see that using linkWithPopup return error auth/credential-already-in-use if the Account exist so then I must use signInWithCredential. This works ok however so far.

Reading about linkWithCredential I don’t see what to do if the Google account is already in use at Firebase. That linkWithCredential would create two account I don’t think so I must maybe do what I did with linkWithPopup like signInWithCredential

This two does the same thing in the end; when to use what, or what did I miss?

Advertisement

Answer

linkWithCredential() links the account with credentials that you obtained from a previous sign-in.

linkWithPopup() links the account with the given provider, guiding the user through the authentication flow for that provider. The credentials will be automatically obtained from that sign-in.

So, if you already have credentials for an account where the user already signed in, use linkWithCredential. If you don’t have user credentials, and you need to user to go through a sign-in flow to get them, use linkWithPopup().

The end result is the same in either case – the Firebase Auth account for the currently signed in will be linked to the other account (Google, Facebook, etc) where the user has proved their identity.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement