0

I've followed this post on Medium to try to implement firebase authentication: https://blog.invertase.io/getting-started-with-firebase-authentication-on-react-native-a1ed3d2d6d91

I firstly implemented the Social Authentication with Facebook and it worked fine, but after that, when I successfully finished the Google Authentication part, the Facebook part was stuck at the line

return firebase.auth().signInWithCredential(credential);

Because It didn't return the user Promise after that so the Firebase onAuthStateChanged cannot log the user in

The function that handle facebook authentication:

onLoginOrRegisterFacebook = () => {
    LoginManager.logInWithReadPermissions(["public_profile", "email"])
      .then(result => {
        if (result.isCancelled) {
          return Promise.reject(new Error("The user cancelled the request"));
        }
        // Retrieve the access token
        return AccessToken.getCurrentAccessToken();
      })
      .then(data => {
        // Create a new Firebase credential with the token
        const credential = firebase.auth.FacebookAuthProvider.credential(
          data.accessToken
        );
        // Login with the credential
        return firebase.auth().signInWithCredential(credential);
      })
      .then(user => {
      

      })
      .catch(error => {
        const { code, message } = error;
       
      });
  };

The Facebook Sign In Method in Google Firebase Authentication Console is also enabled with enough information of my FB app, I also paste the OAuth redirect URI to my Facebook app configuration, and the Dashboard of Facebook Developer also successfully shows the installed app user.

Nhat Truong
  • 21
  • 1
  • 3
  • Did you see any error messages from dev console? – Ti Wang Jan 31 '18 at 01:55
  • There was no error in react-native log-android as well as Reactotron. I tried to log the Facebook credential after the line const credential = firebase.auth.FacebookAuthProvider.credential( data.accessToken ); and it show that there were 3 key-value pair including token, secret, providerId but the element secret was blank. Is this the problem ? – Nhat Truong Jan 31 '18 at 03:40
  • I don't think so. Did you see anything printed in your last catch block? I mean did signInWithCredential throw any errors? – Ti Wang Jan 31 '18 at 17:44
  • Thank you for your support. Now i know what the problem is. It belongs to the "same email for both providers" problem, but i really got angry due to the fact that there was no error showed in the log. I wasted 2 days for finding that bug. According to this related stackoverflow post: https://stackoverflow.com/questions/37947944/authentication-using-facebook-at-first-and-then-google-causes-an-error-in-fireba, I must use the account linking solution, right? – Nhat Truong Feb 01 '18 at 13:39
  • You are right. You have to link the new account to the existing account who has the same email. – Ti Wang Feb 01 '18 at 17:45

0 Answers0