dev-resources.site
for different kinds of informations.
Authentication in Android Project with Firebase.
Published at
1/13/2025
Categories
kotlin
android
firebase
mobile
Author
harsh_lade
Author
10 person written this
harsh_lade
open
Introduction
We discussed the benefits and implementation of Firebase in our Android Studio Project. In this article, we will see the practical use of Firebase, we will learn how to use Authentication for your app using Firebase.
Prerequisites
- Firebase has already been integrated in project.
-
google-service.json
file has been added in your project.
Implementation
###1. Add Firebase authentication dependency in your build.gradle
:
dependencies{
//other dependencies...
implementaion("com.google.firebase:firebase-auth:22.1.0")
}
2. Initialize authentication in your App.
Add a Firebase instance in your project.
private val firebaseInstance=FirebaseAuth.getInstance()
3. Add Functionalities to Your App.
- Sign In Functionality.
fun signIn(email:String, password: String, context: Context) {
firebaseInstance
.signInWithEmailAndPassword(email, password)
.addOnCompleteListener { task->
if(task.isSuccessful) {
val user = firebaseInstance.currentUser?.email
Toast.makeText(context, "Sign in successful- $user", Toast.LENGTH_SHORT).show()
}
else{
Toast.makeText(context, "Failed, error: ${task.exception?.message}", Toast.LENGTH_SHORT).show()
}
}
}
- Sign Up functionality.
fun signUp(email:String, password: String, context: Context){
firebaseInstance.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener { task->
if(task.isSuccessful) {
val user = firebaseInstance.currentUser?.email
Toast.makeText(context, "Sign-up successful- $user", Toast.LENGTH_SHORT).show()
}
else{
Toast.makeText(context, "Failed, error: ${task.exception?.message}", Toast.LENGTH_SHORT).show()
}
}
}
- Sign Out Functioality.
fun signOut(context: Context){
firebaseInstance.signOut()
Toast.makeText(context, "User signed out.", Toast.LENGTH_SHORT).show()
}
- Manage User Session.
fun checkUserSession() {
val user = firebaseAuth.currentUser
if (user != null) {
println("User already signed in: ${user.email}")
} else {
println("No user signed in.")
}
}
Conclusion.
We have discussed the application of Firebase. We will learn more about Firebase in upcoming lecture, so stay tuned.
kotlin Article's
30 articles in total
Using SVGs on Canvas with Compose Multiplatform
read article
Kotlin Generics Simplified
read article
Understanding Quick Sort in Kotlin : A Beginner's Guide
read article
Understanding Selection Sort in Kotlin: A Beginner's Guide
read article
Wednesday Links - Edition 2025-01-08
read article
Testing Pi Logic integrations.
read article
Understanding (a bit of) the Gradle Kotlin DSL
read article
Android TreeView(Hierarchy based) with Kotlin
read article
Creando un notebook con Jupyter y Kotlin
read article
Getting Started with Android Testing: Building Reliable Apps with Confidence (Part 3/3)
read article
Getting Started with Android Testing: Building Reliable Apps with Confidence (Part 2/3)
read article
Understanding Room Database in Android: A Beginner's Guide
read article
Fixing Rounded Navigation Bar Corner Padding in Jetpack Compose
read article
Getting Started with Android Testing: Building Reliable Apps with Confidence (Part 1/3)
read article
My conference year
read article
Authentication in Android Project with Firebase.
currently reading
Learn Firebase for Android Development from Scratch, a beginner guide.
read article
๐งน Improve Filtering with the Predicate Interface!
read article
How to make the best of a slow machine running on limited resources with a Windows environment as a Java Engineer
read article
How to implement detekt in Spring Boot + Kotlin + Gradle project
read article
How to Create and Publish an Android Library for Beginners
read article
Pub-sub Redis in Micronaut
read article
ISBN Stacks โ A look at a possible Spring Application implementation without annotations
read article
Protecting Applications with Kong security plugins and using StatsD to monitor system states โ A healthy camera story
read article
Configurable Kong API Gateway with Micronaut Services in Kotlin โ A very odd Yucca tribute concert
read article
Learning AWS with Localstack and Reactive Kotlin โ A stamps and coins implementation
read article
Coroutines, Distributed Cache, Resilience, and Replication in Kotlin โ Making a VMAโs application
read article
From Paris to Berlin โ Creating Circuit-Breakers in Kotlin
read article
Understanding Merge Sort in Kotlin: A Beginner's Guide
read article
City Library โ An advanced guide to Circuit Breakers in Kotlin
read article
Featured ones: