13
votes

I am unable to to sucessfully to do , I followed the following steps as instructed on Firebase Docs:

  1. Signed in use using existing auth provider(my case:facebook).
  2. Complete the sign-in flow for the new authentication provider up to, but not including, calling one of the Auth.signInWith methods.(my case: i want to link email & password and Google OAUth). So this is the step i'm unclear about, I created a new provider using var provider = new firebase.auth.GoogleAuthProvider(); and I did not do Firebase.auth().signInWithPopup(provider) .
  3. Then to get authcredential for google I run var credential = firebase.auth.GoogleAuthProvider.credential( googleUser.getAuthResponse().id_token); (I get an undefined googleUser error) this error seems appropriate since I have not signed in using Google Oauth but thats what the 2nd steps states(not to signin)
  4. And then this command to link with the current user who is on a Facebook Provider auth.currentUser.link(credential)

My understanding is that currentUser needs to be linked to my existing Provider(Facebook). It seems that credential variable for google is never computed. Anyone with a functional code example would really help.

2

2 Answers

11
votes

If you want to manually link a google and email/pass account to existing facebook only firebase user, you can do the following: First, the user should be signed in to Facebook. Link the google user:

var provider = new firebase.auth.GoogleAuthProvider();
auth.currentUser.linkWithPopup(provider);

Then link the email/pass account:

auth.currentUser.linkWithCredential(firebase.auth.EmailAuthProvider.credential(auth.currentUser.email, 'password'))

All these accounts to be linked must be new and not already linked.

1
votes

@bojeil I have read your question and I found the way to log in both Google and Facebook logins having the same email account. First, in the Firebase, you need to allow

"Multiple accounts per email address"

Allow multiple accounts per email address

Now you can log in with both Facebook having "[email protected]" & Google having the same email name as "[email protected]".But you will encounter the email as "null" for the second login having the same email. You can get over the null problem by using the below snippet.

Just use this snippet in on success task from the firebase:

Map profile = task.getResult().getAdditionalUserInfo().getProfile();

Object email = profile.get("email"); /// Obtaining the email from the use though we use same email form facebook and Google log in accounts.

By this way, you can log in into both Facebook and Google logins using the same email.

I hope you got your doubt cleared with this info. Can you please get back to me if this suits your question?.

Thank you.