Facebook Login with Firebase in React Native Error 400

I'm having trouble registering a user in Firebase with his credentials in RN. Facebook and Firebase apps are configured correctly as everything works as expected in Swift. The OAuth redirect URI is also configured correctly.

However, when I try to do the same process from RN, it fails. My setup is as follows, when the user enters my login button, I call the FB LoginManager.logInWithReadPermissions(['public_profile', 'email'])

and on success I call FirebaseManager

(this is my own class for managing Firebase) signUpWithFacebook()

. I am getting the FB access token correctly and I can see that a credential object is being created.

However, Firebase always returns an error:

{"error": {"errors": [{"domain": "global", "reason": "invalid", "message": "A system error occurred"}], "code": 400, "message": "A system error has occurred"}}

FirebaseManager looks like this:

import { AsyncStorage, NativeModules } from "react-native";
import * as firebase from 'firebase';

const firebaseConfig = {
    apiKey: "key",
    authDomain: "domain",
    databaseURL: "db_url",
    projectId: "project_id",
    storageBucket: "storage_bucket"
};
const firebaseApp = firebase.initializeApp(firebaseConfig);

const FBSDK = require('react-native-fbsdk');
const {
    AccessToken
} = FBSDK;

export default class FirebaseManager {

    constructor() {
        // Some logic...
    }

    signUpWithFacebook() {
        AccessToken.getCurrentAccessToken().then((data) => {
            let accessToken = data.accessToken
            console.log('FB accessToken: ' + accessToken)

            const provider = new firebase.auth.FacebookAuthProvider();
            const credential = provider.credential(accessToken);
            console.log('FB credential: ' + credential)

            firebase.auth().signInWithCredential(credential)
                .then()
                .catch((error) => {
                    console.log('Failed to sign in Firebase with Facebook. ' + error)
              })
        })
    }
}

      

I would also like to point out that Firebase anonymity and email / password authentication work without issue.

My workaround for now is registering Facebook with Swift and returning the user object to the RN using the bridge and RN NativeModules

.

Additional information about my project:

react-native: 0.44.2

firebase: 4.0.0

react-native-fbsdk: 0.6.0

Any help would be appreciated!

+3


source to share


1 answer


There will probably be a long shooting, but it looks VERY similar to the problem in the firebase JS SDK. The solution was to not instantiate FacebookAuthProvider by changing these lines:

const provider = new firebase.auth.FacebookAuthProvider();
const credential = provider.credential(accessToken);

      



:

var credential = firebase.auth.FacebookAuthProvider.credential(accessToken);

      

0


source







All Articles