AirBnB Clone with React Native Part 3: Email Authentication with Firebase
Tags: authentication, heartbeat, firebase, reactnative
Published: 2019-08-21 15:35:44

---
title: AirBnB Clone with React Native Part 3: Email Authentication with Firebase
published: true
tags: authentication,heartbeat,firebase,react-native
canonical_url: https://heartbeat.fritz.ai/airbnb-clone-with-react-native-part-3-email-authentication-with-firebase-2153a00175ab
cover_image: https://cdn-images-1.medium.com/max/1024/1*wZNCtAgkUobkqMEmhX-zXA.jpeg
series: Building a React Native Airbnb clone
---

### Make a fully functional real estate app in minutes
Become the next Trulia, Zillow or Airbnb by releasing a real estate app for both iOS and Android in minutes. Download our functional [React Native Real Estate](https://www.instamobile.io/app-templates/real-estate-app-template-react-native/) app template, integrated with Firebase Backend, to literally launch your own app today. Crafted with extreme attention to details, this beautiful app template written in React Native represents the best way to jumpstart the development of your new mobile app.


This tutorial is the third chapter of our implementation of an Airbnb clone in React Native. In previous chapters, we’ve successfully implemented a Home Screen UI and Login Screen UI:

- [AirBnB Clone with React Native Part 1: Home Screen UI](https://dev.to/kris/airbnb-clone-with-react-native-part-1-home-screen-ui-3dnl)
- [AirBnB Clone with React Native Part 2: Login Screen UI](https://dev.to/kris/airbnb-clone-with-react-native-part-2-login-screen-ui-3nn5)

In part 3, we’re going to continue from where we left off in part two. Here, we’ll implement email authentication in our Login Screen UI. Basically, we’re going to integrate a user authentication mechanism with Firebase. For simplicity, we’re going to use basic Email and Password authentication first.

> If you’re interested in working with other authentication mechanisms, check out my tutorial on [implementing Facebook login on Android with React Native](https://dev.to/kris/implementing-facebook-login-on-android-with-react-native-and-firebase-1bj2).

Let’s get started!

### Setting up the Firebase package

First, we need to set up our Firebase package. For this, we’re going to install the react-native-firebase package into our project, which simply integrates Firebase into our project. It facilitates a light-weight layer on-top of the native Firebase SDKs while mirroring the Firebase Web SDK’s API as closely as possible. To install this package, we can use yarn or npm:

Using yarn:

{% gist https://gist.github.com/krissnawat/95d0196c54fd829484fc9c0192f59c76 %}

Using npm:

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

After using the above commands in our project console, we should have successfully integrated the react-native-firebase package. But we can’t forget to link the package with the react-native package itself. To do this, we can use the following commands:

{% gist https://gist.github.com/krissnawat/09ff8be40b97435b1d4f5649cddb72e8 %}

#### Install Pod Requirement

After linking the required package, we need to install the required Pod. For this, we need to open ios/Podfile and add a line after target 'airbnbclone' do, as shown in the example below:

{% gist https://gist.github.com/krissnawat/1e211737afd45c99e85a5ea2a7ce80af %}

After adding the line, we need to run the command:

pod install

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

As we can see, we have successfully installed the required Pod.

#### Initializing Firebase

Now its time to initialize Firebase into our project. To initialize the native SDK in our app, we’ll need to add the following piece of codes to our ios/airbnbclone/AppDelegate.m file.

At the top of the file, we need to add:

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

At the beginning of the didFinishLaunchingWithOptions:(NSDictionary \*)launchOptions method, we need to add the following line:

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

The pieces of codes mentioned above are shown in the IDE screenshot below:

![](https://cdn-images-1.medium.com/max/444/1*QAIRy_lTYWThvHcc-SNRBw.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)

#### Adding GoogleService-Info

Lastly, we need to head over to the Firebase console and create a new app named ‘ **_airbnbclone’_**. The Firebase app is shown in the screenshot provided below:

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

In the screenshot, we can see the ‘Add app’ button. Click on this and choose iOS and add your iOS bundle ID, as shown in the screenshot below:

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

If we want to know our bundle ID, we need to open the ios folder in Xcode where we’ll see bundle identifiers, from which we need to grab the value. The Xcode project with bundle identifiers is shown in the screenshot below:

![](https://cdn-images-1.medium.com/max/993/1*AN1FkwR8rV4yw9y1Vq-EWw.png)

Then, we need to click on ‘Register app’ in Firebase and follow the instructions given below:

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

Finally, after everything is done, we need to run the command:

{% gist https://gist.github.com/krissnawat/2e1245a6f0680e10f8a96e71d675a999 %}

This will run the iOS emulator in our project.

### Getting data in the form and setting it up to state

Now, let's move on to the coding part of the tutorial. Here, we need to create two functions— handleEmailChange and handlePasswordChange to handle email and password inputs as shown in the code snippet below:

{% gist https://gist.github.com/krissnawat/58b873ba24d1165635bfdeeeb73a927e %}

And then, we need to add these functions to an onChangeText event.

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

Next, we need to add an onChangeText event to the child component. For this, we need to open src/components/form/InputField.js and add a few new props: inputType, customStyle, and onChangeText:

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

Then, we need to add an onChangeText event to the child component, also passing new props, as shown in the code snippet below:

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

After this, we successfully pass the form data to our parent component.

### Handling the Firebase login

Now it’s time to handle the Firebase login with authentication. In order to activate Firebase in our project, we simply need to call a function named Login() and paste the code given below:

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

Then we add a trigger to our Login() function. We do this by using a button and passing the event to the child component, which is the same process we did before:

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

Next we need to add the event to the child component, as well:

{% gist https://gist.github.com/krissnawat/341e343a877341934a0c206bc43e1501 %}

### Trying it out

We’ve successfully integrated Firebase login authentication to our login screen UI. Now we can test it out by changing the functions to signInWithEmailAndPassword for the login and createUserWithEmailAndPassword to create a new user. First, let's try creating a user:

![](https://cdn-images-1.medium.com/max/995/1*3EukUQC5uenX117RUYtOcA.png)

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

Now that we have a new user, we switch the function to signInWithEmailAndPassword and try the login function. We can see the result of our login attempts in the console simulations below:

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

Our test works! We’ve now successfully completed and tested the implementation of Firebase authentication in our AirBnB clone login screen.

### Conclusion

In part 3, we’ve learned how to set up the react-native-firebase package and link it to the react-native package in our project. Also, we learned how to activate Firebase in React Native and how to get the form value as a child component.

Lastly, we followed an in-depth, step-by-step guide to using Firebase as an email authentication mechanism. The overall code for this tutorial is available on [GitHub](https://github.com/krissnawat/airbnbclone-with-react-native). In the next chapter, we’re going to continue working with basic form validation.

### Resource

[Authenticate with Firebase using Password-Based Accounts using Javascript | Firebase](https://firebase.google.com/docs/auth/web/password-auth?authuser=0)

> The next revolution in mobile development? Machine learning. [Learn more about how Fritz can help you build a new kind of mobile experience.](https://fritz.ai?utm_campaign=fomo1&utm_source=heartbeat)

_Editor’s Note:_[_Join Heartbeat on Slack_](http://bit.ly/heartbeatslack) _and follow us on_[_Twitter_](https://twitter.com/fritzlabs) _and_[_LinkedIn_](https://www.linkedin.com/company/fritz-labs-inc/) _for all the latest content, news, and more in machine learning, mobile development, and where the two intersect._

* * *