Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Link Multiple Auth Providers to an Firebase Account?

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.

like image 391
jasan Avatar asked Jun 11 '16 21:06

jasan


People also ask

Can you create a user with the same credentials in Firebase?

You can allow users to sign in to your app using multiple authentication providers by linking auth provider credentials to an existing user account. Users are identifiable by the same Firebase user ID regardless of the authentication provider they used to sign in.

How do I link Firebase Auth to firestore?

Enable authentication for your Firebase project to use Firestore: In the Firebase console, click Authentication from the navigation panel. Go to the Sign-in Method tab. Enable Email/Password and Google authentication.


1 Answers

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.

like image 187
bojeil Avatar answered Nov 10 '22 07:11

bojeil