AirBnB Clone with React Native Part 8: Firebase Facebook Login (iOS)
Tags: reactnative, mobiledevelopment, firebase, javascript
Published: 2019-11-05 04:29:26

---
title: AirBnB Clone with React Native Part 8: Firebase Facebook Login (iOS)
published: true
date: 2019-11-04 16:16:01 UTC
tags: react-native,mobile-development,firebase,javascript
canonical_url: https://heartbeat.fritz.ai/airbnb-clone-with-react-native-part-8-firebase-facebook-login-ios-f2cd4b73fe7d
cover_image: https://cdn-images-1.medium.com/max/1024/0*7dfvDsv3ZRtVTsan.jpeg
---


This tutorial is the eighth chapter of our implementation of an Airbnb clone in React Native. In the previous chapter, we successfully implemented the “Forgot Password” feature with Firebase. In case you need to get caught up, here are links to parts 1–7: and inspired by [React native real estate template](https://www.instamobile.io/app-templates/real-estate-app-template-react-native/) by Instamobile

- [AirBnB Clone with React Native Part 1: Home Screen UI](https://heartbeat.fritz.ai/airbnb-clone-with-react-native-part-1-home-screen-ui-b5ed1c9278ae)
- [AirBnB Clone with React Native Part 2: Login Screen UI](https://heartbeat.fritz.ai/airbnb-clone-with-react-native-part-2-login-screen-ui-999773e860e4)
- [AirBnB Clone with React Native Part 3: Email Authentication with Firebase](https://heartbeat.fritz.ai/airbnb-clone-with-react-native-part-3-email-authentication-with-firebase-2153a00175ab)
- [AirBnB Clone with React Native Part 4: Login error notifications](https://heartbeat.fritz.ai/airbnb-clone-with-react-native-part-4-login-error-notifications-580beb4fc03c)
- [AirBnB Clone with React Native Part 5: Loading Modal Implementation](https://heartbeat.fritz.ai/airbnb-clone-with-react-native-part-5-loading-modal-implementation-8a399154ac02)
- [AirBnB Clone with React Native Part 6: Animated Checkmarks](https://heartbeat.fritz.ai/airbnb-clone-with-react-native-part-6-animated-checkmarks-5917e4972702)
- [AirBnB Clone with React Native Part 7: “Forgot Password?” with Firebase](https://heartbeat.fritz.ai/airbnb-clone-with-react-native-part-7-forgot-password-with-firebase-14ccbf6afa21)

In part 8, we’re going to continue where we left off by implementing the Firebase Facebook Login feature for iOS. Facebook login is one of the most used social login features for both websites and mobile applications.

These social logins make it easier for users to log in from their social media accounts. They won’t have to do the work of filling out long registration forms. With just a click of a button, users can log in with their social credentials.

We might remember that in the first part of this tutorial series, we added the Facebook login button to the Login screen. Here, the idea is to add functionality to that button using Firebase’s Facebook login system so that users can log in by just clicking the button.

> Note that this tutorial provides guidance for setting up Firebase Facebook login for iOS only. For a look at the comparable implementation on Android, [check out this tutorial](https://heartbeat.fritz.ai/implementing-facebook-login-on-android-with-react-native-and-firebase-2cdde7f84a5c?source=---------37------------------)

> Looking for new ways to elevate your mobile app’s user experience? [With Fritz AI, you can teach your apps to see, hear, sense, and think. Learn how and start building with a free account.](https://www.fritz.ai/product/standard.html?utm_campaign=buildapps9&utm_source=heartbeat)

#### Setting up the Facebook SDK package

First, we’re going to install the Facebook SDK, which provides us with components and an API to implement Facebook login and other features. In order to do that, we need to install the [react-native-fbsdk](https://github.com/facebook/react-native-fbsdk) package into our project using the following command:

{% gist https://gist.github.com/krissnawat/6b6b0c82fd89522ce889b5a562322c7b %}

After installing the package, we need to run the following command to link the package with the native part of our React Native project:

{% gist https://gist.github.com/krissnawat/b59144d6938ec634305d886f7200e1c0 %}

Now we need to navigate to the ‘./ios/’ directory in our project command prompt and run the following command:

{% gist https://gist.github.com/krissnawat/bcce996ec48ac5154a1bdd84c74d0681 %}

Here, cd ios is used to enter the iOS directory, and pod install will configure the dependencies with the iOS app.

#### Configuring iOS files

In this step, we need to update some iOS files with Facebook App IDs and the app name. For this, we can follow the instructions provided in the [documentation](https://developers.facebook.com/docs/ios/getting-started/) of the Facebook developer console for iOS.

Next, we open our project in Xcode and then open the info.plist file. Then, we need to copy the code from the following code snippet into the info.plist file:

{% gist https://gist.github.com/krissnawat/62c376414dca682bc45d624145c985da %}

Then, we need to replace the app-id and app-name with the proper values as shown in the screenshot below:

![](https://cdn-images-1.medium.com/max/777/1*tjZeub5TZC7c1be4l9C5Mg.png)

The last file we need to configure is the appdelegate.m file. Once opened, we need to copy the code from Facebook’s documentation (linked above) and paste it into the appdelegate.m file. After this, move the code provided in the following code snippet into our appdelegate.m file:

{% gist https://gist.github.com/krissnawat/c73d314fb2fd39e70c56714ccc211a0a %}

Next, we need to import FBSDKCorkit.h into our appdelegate.m file, as highlighted in the screenshot below:

![](https://cdn-images-1.medium.com/max/1024/1*xxY50dvQc1vPzln9VDA95w.png)

> The next revolution in mobile development? Machine learning. Don’t miss out on the latest from this emerging intersection. [Sign up for weekly updates from our crew of mobile devs and machine learners.](https://www.fritz.ai/newsletter?utm_campaign=heartbeat-newsletter-fomo2&utm_source=heartbeat)

#### Configuring the Login Button

Here, we’re going to configure the Facebook login button, which we’ve already added to our LoggedOut.js file from the first part of this tutorial series.

Now we need to go to the LoggedOut.js file of our React Native project. Import the LoginManager component from the react-native-fbsdk package, as shown in the code snippet below:

```
import { LoginManager,AccessToken } from 'react-native-fbsdk';
```

Since we already have the Facebook Login button, we don’t need to implement it. We just need to add the functionality to the button.

To do this, we’re going to create a function called FacebookLogin(), which will contain the configuration for the login. We need to copy the code from the Firebase documentation and paste it inside the FacebookLogin() function, as shown in the code snippet below:

{% gist https://gist.github.com/krissnawat/16b26b801c051ecc338c27e5e88e5595 %}

Here, we’ve implemented the FacebookLogin() function as an asynchronous function. First, we activate the Facebook login. Then, we’ll get an access token in return, which we save to Firebase. And when Firebase returns the login credentials, we manually authenticate to Firebase. And after ensuring that everything is a success, we navigate to the Home screen.

Next, we need to add the FacebookLogin() function to the onPress event of the RoundedButton component, which represents the Facebook login button:

{% gist https://gist.github.com/krissnawat/a3852f4504b5216c7daf826c8c9f1e24 %}

Lastly, we need to enable the Facebook Login feature on Firebase, as shown in the screenshot below:

![](https://cdn-images-1.medium.com/max/1019/1*XF42PWSXkC2HVE-TD9sw9Q.png)

Now, if we re-run the project in the iOS emulator for testing, we’ll get the following result:

![](https://cdn-images-1.medium.com/max/363/1*fj72EPcDbuQV_VcSuRQ0pQ.gif)

As we can see, when we press the Facebook Login button, we’re redirected to the Facebook interface in order to ensure that we do indeed want to continue with the selected Facebook account. Then, after we press ‘Continue’, we’re successfully logged in with our Facebook account and redirected to the Home screen.

And that’s it! We’ve now successfully implemented the Firebase Facebook Login feature (for iOS) in our AirBnB Clone with React Native tutorial series.

### Conclusion

In this part of our AirBnB clone tutorial series, we learned how to implement Facebook login with Firebase in React Native for iOS. First, we installed the Facebook SDK package. Then, we went step-by-step in configuring the native iOS files in order to integrate them with Facebook IDs. Then, we used the component from the Facebook SDK package to configure the Facebook login button.

The implementation of [Facebook login on Android](https://heartbeat.fritz.ai/implementing-facebook-login-on-android-with-react-native-and-firebase-2cdde7f84a5c?source=---------37------------------) is available in another tutorial (not included in this series). For the next part in our series, we’ll learn how to implement sessions after a successful login.

_Editor’s Note:_[_Heartbeat_](http://heartbeat.fritz.ai) _is a contributor-driven online publication and community dedicated to exploring the emerging intersection of mobile app development and machine learning. We’re committed to supporting and inspiring developers and engineers from all walks of life._

_Editorially independent, Heartbeat is sponsored and published by_[_Fritz AI_](http://fritz.ai)_, the machine learning platform that helps developers teach devices to see, hear, sense, and think. We pay our contributors, and we don’t sell ads._

_If you’d like to contribute, head on over to our_[_call for contributors_](https://heartbeat.fritz.ai/call-for-contributors-october-2018-update-fee7f5b80f3e)_. You can also sign up to receive our weekly newsletters (_[_Deep Learning Weekly_](https://www.deeplearningweekly.com/) _and_[_Heartbeat_](https://www.fritz.ai/newsletter)_), join us on_[](https://join.slack.com/t/fritz-ai-community/shared_invite/enQtNTY5NDM2MTQwMTgwLWU4ZDEwNTAxYWE2YjIxZDllMTcxMWE4MGFhNDk5Y2QwNTcxYzEyNWZmZWEwMzE4NTFkOWY2NTM0OGQwYjM5Y2U)[_Slack_](http://fritz.ai/slack)_, and follow Fritz AI on_[_Twitter_](https://twitter.com/fritzlabs) _for all the latest in mobile machine learning._

* * *