Get Started with Firebase Authentication on Android Stay organized with collections Save and categorize content based on your preferences.
Connect your app to Firebase
If you haven't already,add Firebase to your Android project.
AddFirebase Authentication to your app
In yourmodule (app-level) Gradle file(usually
<project>/<app-module>/build.gradle.ktsor<project>/<app-module>/build.gradle),add the dependency for theFirebase Authentication library for Android. We recommend using theFirebase Android BoMto control library versioning.dependencies{// Import theBoM for the Firebase platformimplementation(platform("com.google.firebase:firebase-bom:34.9.0"))// Add the dependency for theFirebase Authentication library// When using theBoM, you don't specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-auth")}
By using theFirebase Android BoM, your app will always use compatible versions of Firebase Android libraries.
(Alternative) Add Firebase library dependencies without using theBoM
If you choose not to use theFirebase BoM, you must specify each Firebase library version in its dependency line.
Note that if you usemultiple Firebase libraries in your app, we strongly recommend using theBoM to manage library versions, which ensures that all versions are compatible.
dependencies{// Add the dependency for theFirebase Authentication library// When NOT using theBoM, you must specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-auth:24.0.1")}
To use an authentication provider, you need to enable it in theFirebase console. Go to the Sign-in Method page in theFirebase Authenticationsection to enable Email/Password sign-in and any other identity providersyou want for your app.
(Optional) Prototype and test withFirebase Local Emulator Suite
Before talking about how your app authenticates users, let's introduce a set oftools you can use to prototype and testAuthentication functionality:Firebase Local Emulator Suite. If you're deciding among authentication techniquesand providers, trying out different data models with public and private datausingAuthentication andFirebase Security Rules, or prototyping sign-in UI designs, being able towork locally without deploying live services can be a great idea.
AnAuthentication emulator is part of theLocal Emulator Suite, whichenables your app to interact with emulated database content and config, aswell as optionally your emulated project resources (functions, other databases,and security rules).
Using theAuthentication emulator involves just a few steps:
- Adding a line of code to your app's test config to connect to the emulator.
- From the root of your local project directory, running
firebase emulators:start. - Using theLocal Emulator Suite UI for interactive prototyping, or theAuthentication emulator REST API for non-interactive testing.
A detailed guide is available atConnect your app to theAuthentication emulator.For more information, see theLocal Emulator Suite introduction.
Now let's continue with how to authenticate users.
Check current auth state
Declare an instance of
FirebaseAuth.Kotlin
privatelateinitvarauth:FirebaseAuth
Java
privateFirebaseAuthmAuth;
In the
onCreate()method, initialize theFirebaseAuthinstance.Kotlin
// Initialize Firebase Authauth=Firebase.auth
Java
// Initialize Firebase AuthmAuth=FirebaseAuth.getInstance();
When initializing your Activity, check to see if the user is currently signedin.
Kotlin
publicoverridefunonStart(){super.onStart()// Check if user is signed in (non-null) and update UI accordingly.valcurrentUser=auth.currentUserif(currentUser!=null){reload()}}
Java
@OverridepublicvoidonStart(){super.onStart();// Check if user is signed in (non-null) and update UI accordingly.FirebaseUsercurrentUser=mAuth.getCurrentUser();if(currentUser!=null){reload();}}
Sign up new users
Create a newcreateAccount method that takes in an email address and password,validates them, and then creates a new user with thecreateUserWithEmailAndPasswordmethod.
Kotlin
auth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this){task->if(task.isSuccessful){// Sign in success, update UI with the signed-in user's informationLog.d(TAG,"createUserWithEmail:success")valuser=auth.currentUserupdateUI(user)}else{// If sign in fails, display a message to the user.Log.w(TAG,"createUserWithEmail:failure",task.exception)Toast.makeText(baseContext,"Authentication failed.",Toast.LENGTH_SHORT,).show()updateUI(null)}}
Java
mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this,newOnCompleteListener<AuthResult>(){@OverridepublicvoidonComplete(@NonNullTask<AuthResult>task){if(task.isSuccessful()){// Sign in success, update UI with the signed-in user's informationLog.d(TAG,"createUserWithEmail:success");FirebaseUseruser=mAuth.getCurrentUser();updateUI(user);}else{// If sign in fails, display a message to the user.Log.w(TAG,"createUserWithEmail:failure",task.getException());Toast.makeText(EmailPasswordActivity.this,"Authentication failed.",Toast.LENGTH_SHORT).show();updateUI(null);}}});
Add a form to register new users with their email and password and call this newmethod when it is submitted. You can see an example in ourquickstart sample.
Sign in existing users
Create a newsignIn method which takes in an email address and password,validates them, and then signs a user in with thesignInWithEmailAndPassword method.
Kotlin
auth.signInWithEmailAndPassword(email,password).addOnCompleteListener(this){task->if(task.isSuccessful){// Sign in success, update UI with the signed-in user's informationLog.d(TAG,"signInWithEmail:success")valuser=auth.currentUserupdateUI(user)}else{// If sign in fails, display a message to the user.Log.w(TAG,"signInWithEmail:failure",task.exception)Toast.makeText(baseContext,"Authentication failed.",Toast.LENGTH_SHORT,).show()updateUI(null)}}
Java
mAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(this,newOnCompleteListener<AuthResult>(){@OverridepublicvoidonComplete(@NonNullTask<AuthResult>task){if(task.isSuccessful()){// Sign in success, update UI with the signed-in user's informationLog.d(TAG,"signInWithEmail:success");FirebaseUseruser=mAuth.getCurrentUser();updateUI(user);}else{// If sign in fails, display a message to the user.Log.w(TAG,"signInWithEmail:failure",task.getException());Toast.makeText(EmailPasswordActivity.this,"Authentication failed.",Toast.LENGTH_SHORT).show();updateUI(null);}}});
Add a form to sign in users with their email and password and call this newmethod when it is submitted. You can see an example in ourquickstart sample.
Access user information
If a user has signed in successfully you can get their account data atany point with thegetCurrentUser method.
Kotlin
valuser=Firebase.auth.currentUseruser?.let{// Name, email address, and profile photo Urlvalname=it.displayNamevalemail=it.emailvalphotoUrl=it.photoUrl// Check if user's email is verifiedvalemailVerified=it.isEmailVerified// The user's ID, unique to the Firebase project. Do NOT use this value to// authenticate with your backend server, if you have one. Use// FirebaseUser.getIdToken() instead.valuid=it.uid}
Java
FirebaseUseruser=FirebaseAuth.getInstance().getCurrentUser();if(user!=null){// Name, email address, and profile photo UrlStringname=user.getDisplayName();Stringemail=user.getEmail();UriphotoUrl=user.getPhotoUrl();// Check if user's email is verifiedbooleanemailVerified=user.isEmailVerified();// The user's ID, unique to the Firebase project. Do NOT use this value to// authenticate with your backend server, if you have one. Use// FirebaseUser.getIdToken() instead.Stringuid=user.getUid();}
Next Steps
Explore the guides on adding other identity and authentication services:
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.