Firebase User Authentication in android

Firebase authentication in Android is one of the best features to connect users with your application. Firebase is actually cloud that provides the backend. Firebase has own API for communication for example signup and login. So today in this tutorial we will learn how to create a sign-up and sign-in for the user by using Firebase API.

Firebase actually stores the user credential securely in their system while signup did by users and while trying to login it will validate the user credential which is entered at the time of registration. So in this case developer will not worry about to storing the user data on the server and authenticate those.  You can replicate your idea into building the awesome android app even though you do not have server and API.

Ok, Let’s see how to create the register and login with Firebase Authentication in Android. You have followed few simple steps to do configuration on Firebase console. Here are steps:

  1. Please go to Firebase console to create the project. Here you can pass the project name and enter your country name etc.
  2. You have to choose which platform do you want to use. Here we are configuring for Android platform, so I am choosing an option for Android app.
  3. Now you need to enter your package name of your project. Ex: Here my package name is “com.sunil.firebasedatabasetest”. Other fields are optional for debug mode. But if you want to release your app that time you need to pass the SHA-1 key.
  4. Once you have done your step.4 You will get downloaded one google-services.json file. You have to copy this file and paste inside the app folder.

Great done well so far. Now you need to add Firebase dependencies in your Gradle file.

Now I need to create the signup page for the user registration. Here I created SignUpFragment for the user registration. In this fragment, you need to initialize FirebaseAuth to get the instance of FirebaseAuth. 

Once you have the Firebase instance then you required to enter the user email and password to Firebase API to create a user for your application.

Here you will get the response of Firebase for created the user Object. If the object having status success then it means Firebase API have created the user successfully else you can check the error status.

Now let’s create the login page for authenticating the user credential by using Firebase login API. Here I am creating the login page of SignInFragment.

Again you have to get first Firebase authentication instance for validation the user credential by Firebase API. Once you had firebase auth instance then call the Firebase API to validate user email and password.

Here you will get the response of Firebase for authenticating the user Object. If the object having status success then it means Firebase API have authenticated user credential successfully else you can check the error status.

Wrapping Up: As we have seen that Firebase is awesome for instant building the app. Even if you do not have any backend ready till now then you can use the Firebase cloud for a backend to quick start your idea into the Android application. If you want to upload user profile while registering the user then Firebase provides the cloud storage to upload the file or image. Please check this post to upload a file on Firebase Storage in android.

Here are the best offer and recommendation for you to download this. Here you can get access the GitHub source code for Firebase.

Please do subscribe email to get all newsletters of this blog and if you feel that this post will help you to understand then do not forget to subscribe, share and comment below.

Happy Coding 🙂

 

I am a very enthusiastic Android developer to build solid Android apps. I have a keen interest in developing for Android and have published apps to the Google Play Store. I always open to learning new technologies. For any help drop us a line anytime at contact@mobologicplus.com

Leave a Reply

Your email address will not be published. Required fields are marked *