Build React Native Fitness App #13: Expo Facebook login
Tags: expogooglemaps, googleautoexpo, expogooglelogin, expogooglesignin
Published: 2020-02-08 16:34:14

---
title: Build React Native Fitness App #13: Expo Facebook login
published: true
date: 2020-02-08 09:17:24 UTC
tags: expo-google-maps,google-auto-expo,expo-google-login,expo-google-sign-in
cover_image: https://cdn-images-1.medium.com/max/1024/0*lOQI1BSNl5wDSHdi.png
series: Build React native Fitness app
canonical_url: https://kriss.io/build-react-native-fitness-app-13-facebook-login/
---


This tutorial is the thirteenth chapter of the series build fitness tracker this app use for track workouts, diets, or health activities and analyze data and display suggestions. The ultimate goal is to create food and health recommendation using Machine learning. We start with creating an app that the user wants to use and connect to google health and apple heath for gathering everything to create the dataset that applies for train model later. I start with the ultimate goal. Still, we will begin to build a react native app and set up screen navigation with React navigation. inspired by [React native template](http://instamobile.io/) from instamobile

here we continued from the previous chapter that we migrate codebase to Expo our app is not required any advanced feature for now that we can use Expo manage template for a fast workflow but the future if we required feature that out of support we can eject project from manage to bare workflow, for now, Expo team have [release set of package](https://blog.expo.io/you-can-now-use-expo-apis-in-any-react-native-app-7c3a93041331) that we use on manage workflow to individual package that pain is gone

this chapter we will implement Google and Facebook login by Expo package

#### Facebook login

change bundle identifier comes from Expo client app

![](https://cdn-images-1.medium.com/max/992/0*jVqdE1KA9baJlZSd.png)

Add host.exp.Exponent as an iOS _Bundle ID_. then add rRW++LUjmZZ+58EbN5DVhGAnkX4= in Android Key hash

![](https://cdn-images-1.medium.com/max/975/0*0U3Aeg4uoQzGUY_M.png)

add app id to app.json in an extra key that we create a new one

```
"extra": {
     "firebase": {
       "apiKey": "xxxxxxxxxxxxxxxx",
       "authDomain": "rock-elevator-xxxxxxxx.firebaseapp.com",
       "databaseURL": "https://rock-elevator-xxxxxxxx.firebaseio.com",
       "projectId": "rock-elevator-xxxxxxxx",
       "storageBucket": "rock-elevator-xxxxxxxx.appspot.com",
     },
     "facebook": {
       "appId": "xxxxxxxx"
     }
   }
```

now we can come back to LoginScreen.js for finishing login logic

first import firebase and expo facebook package and Expo constant for the handle environment variable

```
import firebase from "../components/Firebase";
import \* as Facebook from "expo-facebook";
import Constants from "expo-constants";
```

then we initial getting AppId from app.json

```
signInWithFacebook = async () => {
  const appId = Constants.manifest.extra.facebook.appId;
  const permissions = ["public\_profile", "email"]; 
  await Facebook.initializeAsync(appId);
  const { type, token } = await Facebook.logInWithReadPermissionsAsync({
    permissions
  });

  if (type == "success") {
    await firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL);
    const credential = firebase.auth.FacebookAuthProvider.credential(token);
    const facebookProfileData = await firebase
      .auth()
      .signInWithCredential(credential); // Sign in with Facebook credential
    console.log(facebookProfileData);
  }
};
```

then start facebook login after getting access token we add to Firebase

and we will see a result like a screenshot below

![](https://cdn-images-1.medium.com/max/466/0*RzfCkqbyczuL8ub-.gif)

#### Conclusion

this chapter we learn how to use Facebook Login with Expo .so simple and sweet Expo handle all everything help us move quickly for next chapter we will try Google login

_Originally published at _[_Kriss_](https://kriss.io/build-react-native-fitness-app-12-facebook-login/)_._

* * *