Authentication with Google and Firebase in React Native

Cüneyt
5bayt
Published in
3 min readJul 31, 2020

This is going to about how to do authentication with Google & Firebase!

After initialized the react native project you need to install some packages for authentication and store data. I will be following the instructions from https://rnfirebase.io.

STEP-1

npm install --save @react-native-firebase/app

You can add the NPM modules via running the codes above on your project’s root directory in console.

STEP-2

After you added the packages on your project you also need to create a project on https://console.firebase.google.com. Then you should add an application to your project. I have added an android application. The important point here while you are adding application to your firebase project Android package name must match with the local project name which can be found with manifest tag in your /android/app/src/main/AndroidManifest.xml file.

What is debug signing certificate?

Some of the google services require providing SHA1 fingerprint for Dynamic Links, Invites and Phone Authentication. For generate the SHA1 fingerprint run command below;

cd android && gradlew signingReport

I added SHA1 fingerprint because google sign-in needs that.

Then copy the SHA1 debug key and paste to your application inside your firebase project on firebase console. If you have done with creating application download the google-services.json file and place it inside of your project at the following location.

/android/app/google-services.json

STEP-3

Here is the final step to prepare android and firebase environment configuration is to add those dependencies below;

/android/build.gradleadd: classpath 'com.google.gms:google-services:4.2.0'

&&

/android/app/build.gradleadd: apply plugin: 'com.google.gms.google-services'

Now we have done with setting configurations and environment up.

GOOGLE SIGN-IN

Added the @react-native-community/google-signin package

These are the code lines after i pressed the sign-in with google button.

Be sure google sign-in is enabled on your application.

Here is my users;

Thats all.

--

--