Kotlin Firebase Authentication – How to Sign Up, Sign In, Sign Out, Verify Email | Android

Firebase Authentication provides backend services, easy-to-use SDKs, and ready-made UI libraries to authenticate users to your app. In this tutorial, we’re gonna build a simple register/login Android App using Firebase Email & Password authentication with Kotlin language.

More Practice:
Kotlin Firebase Authentication – Send Reset Password Email / Forgot Password | Android
Kotlin Firebase Authentication – Google Sign In | Android

I. Way to do

1. Add Firebase to Android Project
1.1 Step by step

– Create new Android App including Kotlin support.
– From menu bar, Tool -> Firebase:

– Assistant window will be shown. Choose Authentication, then click on Email and password authentication:

– At the step 1, click on Connect to Firebase:

– In new Window, choose Create new Project and fill in the name of Firebase Project:

– Click on Connect to Firebase, the Browser will show new Firebase Project that has just been created:

– Come back to Android Studio, at the step 2, click on Add Firebase Authentication to your app:

– You will see a new window that shows the code will be add to build.gradle files. Click on Accept Changes:

– Now view your Project under Project type, you can see google-services.json file:

1.2 Check dependencies

Open Gradle file to check what happens, we can see that some code has been added:
build.gradle (project-level):

build.gradle (App-level):

2. Enable Firebase Auth

Go to Your Firebase Project Console -> Authentication -> SIGN-IN METHOD -> Enable Email/Password:

3. Work with FirebaseAuth object
3.1 Initialize the FirebaseAuth instance

In the Activity onCreate():

3.2 Check if the user is currently signed in

In Activity onStart():

3.3 Sign up a new user

Creates new user with the createUserWithEmailAndPassword() method:

3.4 Sign in an existing user

Login with signInWithEmailAndPassword() method:

3.5 Access user information

Get Information of a user from FirebaseUser object:

3.6 Sign out current user

Log out with signOut() method:

3.7 Send Email Verification

We can send an email to verify User with sendEmailVerification() method. If the task is successful, the email was sent.

This email template is shown on the Email Templates tab in the Authentication section of the Firebase console:

II. Practice

1. Goal

We will build an Android App that can:
– create Account, sign in/sign out, send email verification.
– display current status/user information with verified email status.


2. Technology

– Gradle 3.0.1
– Android Studio 3.x
– Firebase Android SDK 11.x

3. Project Structure


4. Step by step
4.1 Create Android Project & Add Firebase Auth

– Generate new Android Project with package com.javasampleapproach.kotlin.firebase.auth.
– Follow these steps to add Firebase to Android Project.

4.2 Enabling Firebase Auth

Go to Your Firebase Project Console -> Authentication -> SIGN-IN METHOD -> Enable Email/Password:

4.3 Activity

4.4 Set main launcher activity

Open AndroidManifest.xml and make the LoginActivity.java as launcher activity (set it as the first screen).

4.5 Run & Check result

– Use Android Studio, build and Run your Android App.

– Fill in Email & Password field, then click CREATE ACCOUNT button:

– Open Firebase Project Console to check user:

– Click VERIFY EMAIL button:

Then check email:

– Click link in the email to verify, the browser shows:

– Go back to Android App, sign out, then sign in, the account is verified now:

III. Source code


By JavaSampleApproach | December 14, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *