If you are building a pure Expo app, without ejecting it, and are trying to integrate with Firebase Authentication using Facebook Log-In, you are at the right place. In this tutorial, I will be guiding you step by step to set up Firebase Authentication using Facebook OAuth Provider in a Expo project.
You do not want to eject your Expo app, but you want to embrace the simplicity of Firebase Authentication using Facebook as OAuth provider.
In order to use Firebase Auth without ejecting Expo, the only option, which is also the recommended way is to use the Firebase JavaScript/Web SDK.
Using Firebase JavaScript SDK on React Native means we lose the ability to use the pre-built UI and some other features.
3. Paste them into your Firebase Console
Paste your Facebook App ID and App Secret into your Firebase Console
4. Copy the OAuth redirect URI of your Firebase project and paste it to your Facebook Dev Console.
Paste your Firebase OAuth redirect URI into your Facebook Dev Console
Add the following into your Facebook Dev Console:
host.exp.Exponent
rRW++LUjmZZ+58EbN5DVhGAnkX4=
Configure iOS Bundle ID and Android Key Hashes
Up to now, your Facebook app and Firebase project are ready. We can proceed to consume Firebase Auth.
First of all, install firebase
:
npm install --save firebase
To initialize Firebase in Expo, I define my Firebase project attributes and Facebook App ID as an extra
in app.json
manifest file:
Since Firebase App can only be initialized once, I create a new modulefirebase.js
in my Expo project with:
Other parts of our project should no longer import firebase from the default firebase
package but to import from /utils/firebase
.
Flow of log in with Facebook
The logic of logging in with Facebook should be:
The code should be:
Here we have our Firebase Auth set up to handle Facebook login in an Expo app.
There are 3 types of token involved in our scenario:
If you are using Firebase Firestore or Realtime Database, you don’t have to bother about refreshing token as they will be taken care of as a prerequisite of maintaining database connection.
If, however, you are using only Firebase Auth, you will need to refresh the token every hour. To refresh user’s auth token, simply run:
firebase.auth().currentUser.getIdToken(true);
Your claps will definitely drive me further.Feel free to give me some claps. 👏 👏 👏