Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook login in react-native & firebase 3.1

Recently firebase team have released their new version 3.1 of firebase which is compatible with react-native. I'm trying to use the new firebase api with facebook.

Since firebase doesn't support popup or redirect in react-native, i'm using react-native-fbsdk to get the access token but when I'm trying to use auth.signInWithCredential, the sign in fail on

code: "auth/app-not-authorized",
message: "This app, identified by the domain where it's hosted, is not authorized to use Firebase Authentication with the provided API key. Review your key configuration in the Google API console."

This is my code. any help would be very much appreciated.

import { LoginManager, AccessToken} from 'react-native-fbsdk';
import firebase from '../Services/firebase';

const auth = firebase.auth();
const provider = firebase.auth.FacebookAuthProvider;

LoginManager.logInWithReadPermissions(['public_profile'])
.then(loginResult => {
    if (loginResult.isCancelled) {
        console.log('user canceled');
        return;
    }
    AccessToken.getCurrentAccessToken()
    .then(accessTokenData => {
        const credential = provider.credential(accessTokenData.accessToken);
        return auth.signInWithCredential(credential);
    })
    .then(credData => {
        console.log(credData);
    })
    .catch(err => {
        console.log(err);
    });
});
like image 405
atlanteh Avatar asked Jul 03 '16 23:07

atlanteh


People also ask

Is Facebook coded in React Native?

Originally, Facebook only developed React Native to support iOS. However, with it's recent support of the Android operating system, the library can now provide mobile UIs for both platforms. Facebook used React Native to develop its own Ads Manager app, creating both an iOS and an Android version.


1 Answers

We managed to find the problem. It seems that the credentials firebase gave us were obsolete for some reason.
From google console we found out, a new apiKey was somehow generated (maybe during the upgrade to firebase 3?) and the firebase key was marked as Previous key.
Once we updated the new apiKey in our application, everything started working.

like image 168
atlanteh Avatar answered Sep 28 '22 16:09

atlanteh