FIREBASE AUTHENTICATION & EMAIL VERIFICATION IN ANDROID
What is Firebase?
Firebase is a collection of tools and a complete solution for the backend, it handles Authentication, real-time database, cloud firestore, etc, and many more features.
Here in short we will see what tools are present in the Firebase.
Build
Authentication, Cloud firestore, Real-time Database, Storage, Hosting, Functions, machine learning.Release & Monitoring: Crashlytics, Performance, Test lab, App Distribution.
Analytics
Dashboard, Real-time, Events, Conversions, Audiences, Funnels, Custom definitions, Latest release, Retention, DebugView.
Engage
Predictions, A/B testing, Cloud messaging, In-App messaging, Remote config, Dynamic Links, AdMob,Extensions
This blog will cover how to implement Firebase Authentication & Verification of a user using an email address.
Step 1:
The step is we need to create a new project in android studio, in AndroidStudio Go to File -> New -> New Project -> Choose an activity ( I am selecting empty activity you can choose as per your choice ) -> Give a name to project and choose a directory ( where we want to save the project and ) -> Click on finish.
Step 2:
Create a project on the Firebase console.
To register the project on Firebase follows the steps:
- Click on add project, after clicking you will redirect to create project tab.
- On the create project tab give the project name, and click on the continue button.
- Follow the steps and click on create the project.
Here we are done with the project creation on Firebase.
Now we need to add an application, here we will see how to add an android application to the Firebase project.
In our created Firebase project we will see symbols of iOS, Android, Web. So we will see how to register Android applications.
On clicking on the Android symbol, we will redirect to the “Add Firebase to your Android app” screen.
Need to follow 4 steps for registration of application.
Register app
- Add package name of android studio application.
- Add the nickname of the application.
- Click SHA-1 Key.
- Click on the Register app.
Download Config file
- Download the google-services.json file.
- JSON file adds into an android studio project.
Add Firebase SDK into Android Studio project
- Project-level build.Gradle
- App-level build.Gradle
Click on Continue to console
Here we are done with the registration process.
Now we have to enable the authentication function in the Firebase project.
After clicking on the enable button in the sign-in-method option choose the method which you want to use for Authentication. Let’s explore how to Authenticate users using email addresses.
So here I am enabling the email/password option for Authentication.
We can enable more than one authentication method as well.
So here we are done with our Firebase settings.
Let’s see the coding section
Step 3:
Create an instance of FirebaseAuth:
Sign in with Email and Password
Send verification email to a registered user:
To send verification emails to registered users we need to get a FirebaseUser instance.
Send verification email using the below method:
We can check if a user is verified or not:
To reset the password we can send an email to the registered email address:
To SignOut we can use Firebase signOut function like below:
Like this so many features are available in Firebase we can do many more things using Firebase.
Hope it will be helpful to you!!!😊