How to Setup Firebase Email Authentication in Android with Example
Service-access permissions are configured using a mechanism called Firebase authentication. This is accomplished by using Google’s Firebase APIs and Firebase console to create and manage legitimate user accounts. You’ll discover how to integrate Firebase authentication into an Android application in this article.
Step By Step Implementation
Step 1: Create a New Project in Android Studio
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. The code for that has been given in both Java and Kotlin Programming Language for Android.
To do this, launch Android Studio and Create an Empty Activity Project with the following configurations:
- Name: Geeks for Geeks Auth.
- Package name: as com.<your_name>.firebaseauth (without spaces).
- Language: Kotlin.
- Minimum SDK: API 24: Android 7.0
Step 2: Signing in to Android Studio
Find the login button in the right corner, and then tap login to log in to your firebase account.
Step 3: Creating a Firebase Project
A Firebase project is required, which we will later link to our Android app. We will have access to the majority of Firebase services through this project, including authentication and analytics.
There are various steps in this process:
- Launch Firebase, log in using your Google account, and then click the button in the top right corner to get to Firebase Console.
- Create a new firebase project, with the name of the project, like the one below:
3. Enable the analytics:
Step 4: Connecting Firebase with the Application
A Firebase project can be linked to an Android app in two different methods.
- Adding the services configuration file by hand
You can accomplish this by downloading the google-services.json file, inserting it into the root of the Android project, and manually adding the required dependencies.
- You need a running app for this process so that it can communicate with the firebase servers. This shows that the dependencies and project configuration files are functioning as intended.
- Using the Firebase Assistant in Android Studio
This approach takes care of the majority of the work for you and is simpler and more direct. We’ll employ this approach because it is straightforward.
- You can then follow this guide to connect firebase to your app.
Step 5: Adding the Firebase Dependencies
classpath 'com.google.gms:google-services:4.3.13' // Google Services plugin apply plugin: 'com.google.gms.google-services' // Google Services plugin // Import the Firebase BoM implementation platform('com.google.firebase:firebase-bom:30.3.1')
There is one additional Firebase-related detail. We need to enable email and password authentication in our project’s console because we wish to use it.
Go to Authentication > Sign-in method and activate email and password authentication to accomplish that. This is how it ought to seem.
The configuration of Firebase authentication is complete.
Step 6: Adding the Code Sauce
We will now develop the user interface (UI) and backend for our application. Here’s where Kotlin and XML come into play. The firebase APIs will handle the server-side backend for us, so we don’t need to code anything. Isn’t that fantastic?
We need to keep our app organized first. The term “application architecture” refers to this. The three new packages to be added are extensions, utils, and views. Expand the java directory, right-click on the package name directory, and choose to add.
As we go forward, we’ll find out more about them.
Step 7: Working with activity_main.xml
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.