Firebase UI: Authentication using email/password FIREBASE
- Firebase Tutorial
- Features of Firebase
- Android Studio
- Firebase - Environment Setup (with android studio)
- Firebase Assistance - Android Studio
- Firebase Authentication
- Firebase: Google Sign-In Authentication
- Firebase: Facebook Sign-In Authentication
- Firebase: Sign-In Authentication Using Phone Number
- Firebase UI: Authentication using email/password
- Firebase UI: Authentication using email link
- Firebase SDK: Authentication using email/password
- Firebase SDK: Authentication using the email link
- Firebase: Realtime Database
- Firebase: Real-time database setup and configuration
- Firebase: Data Organization in Real-time Database
- Firebase: Realtime Database Reading and Writing
- Firebase: Realtime Database Update and Delete
Firebase UI: Authentication using email and password
As we have discussed previously, there are two authentication methods, i.e.,
Firebase UI and
Firebase SDK. In this section, we will learn how to use the Firebase UI method to perform authentication using the email/password.
Firebase UI is an open-source library and very simple to use. We can customize it because it is open-source. It eliminates boilerplate code(section of code which has to be included in many places with little or no alteration) and promotes best practices both with the user experience and the security. A very simple API provides a simple drop and authentication.
It can handle the flow of all sources of different authentication techniques from email addresses and passwords to phone numbers type identity providers such as Google. It is built on top of the Firebase Auth libraries.
The best practice when we use this library is to maximize the sign-in and sign-up conversion for our application. It enables all automatic single tap signing for our app for returning users and also handles account recovery, account linking.
10 steps to understand the Firebase UI: authentication using the email/password:
In the first step, you need to connect your application with the firebase console. To connect the application with Firebase, go through the following link Firebase - Environment Setup (with android studio)
Once your application is connected to the Firebase, your next step is to import the required libraries for Firebase UI.
apply plugin: 'com.google.gms.google-services'
In the next step, you need to set up or enable authentication methods. For this, you have to enable the email password authentication in the Firebase console.
Now, go to the Android Studio and create an activity for Sign-in and Sign-out.
Now, modify the MainActivity.java file. You have to make sure that your app checks whether or not a user is already signed in from a previous session before invoking Firebase Authentication flow. For this, you have to check the Firebase instances and see if somebody is signed in.
- FirebaseAuth auth=FirebaseAuth.getInstance();
- //Already signed in
- //Not signed in
Now you have to do is actually start signing using the Firebase UI libraries. The entry point for the authentication flow is the Auth UI class. You can retrieve an instance of the Auth UI by AuthUI.getInstances(). Now your need to create the sign-in code first which are as follows:
Now you need to create onActivityResult() because the flow for authentication UI has several response codes. In this function, and after this check the request and response code. If they match, the user will successfully signed-in.
Now let's perform the sign out functionality. Because if a user signs in, then it is also required to have sign out. We will create a sign-out function in the following way:
Apart from Sign-In and Sign-out, we can delete the user also. For this you need to implement delete() function which is called on button click. This will be as followed:
This step is used for adding a new provider. Previously we used Email provider but we can add more providers such as Google, Phone number. This is done in the following way:
For this, we have to enable the phone and Google provider in Firebase console.