A clean, production-ready Android starter boilerplate implementing Google Firebase Authentication (Email/Password registration, sign-in, auto-login session listeners, and sign-out) with ViewBinding and Cloud Firestore readiness.
The Firebase-Auth-Basic-Setup project provides an essential foundation for Android applications requiring user identity management. Utilizing official Firebase SDKs, it implements standard authentication flows, session state persistence, and lifecycle listener monitoring in Kotlin with minimal boilerplate.
- Firebase Authentication Integration: Initializing and managing
FirebaseAuthinstances across multiple Activities. - User Registration & Validation: Creating new user accounts via
createUserWithEmailAndPasswordwith client-side field validation and password confirmation matching. - User Sign-In & Verification: Authenticating credentials with
signInWithEmailAndPasswordand handling asynchronous success/failure callbacks. - Session State Monitoring (
onStart): Inspectingauth.currentUseracross Activity lifecycles to automatically route logged-in users to the main dashboard or unauthenticated users to the login screen. - Clean Architecture with ViewBinding: Utilizing type-safe view binding and modern Android 15 / SDK 36 standards.
graph TD
classDef start fill:#1A365D,stroke:#63B3ED,stroke-width:2px,color:#fff;
classDef auth fill:#7B341E,stroke:#ED8936,stroke-width:2px,color:#fff;
classDef success fill:#234E52,stroke:#38B2AC,stroke-width:2px,color:#fff;
classDef ui fill:#2D3748,stroke:#4FD1C5,stroke-width:2px,color:#fff;
AppLaunch["App Launch / Activity Start"]:::start --> CheckAuth{"auth.currentUser != null?"}
CheckAuth -->|Yes (Session Active)| MainActivity["MainActivity<br/>(Welcome Screen)"]:::success
CheckAuth -->|No (Unauthenticated)| LoginActivity["LoginActivity<br/>(Sign In Screen)"]:::ui
LoginActivity -->|User enters email & pass| SignInAction["auth.signInWithEmailAndPassword()"]:::auth
LoginActivity -->|Navigate| RegisterActivity["RegisterActivity<br/>(Sign Up Screen)"]:::ui
RegisterActivity -->|Validate & Submit| CreateUserAction["auth.createUserWithEmailAndPassword()"]:::auth
SignInAction -->|Success| MainActivity
CreateUserAction -->|Success| MainActivity
MainActivity -->|User taps 'Log Out'| SignOutAction["auth.signOut()"]:::auth
SignOutAction --> LoginActivity
Verifying the user authentication token on every activity startup prevents unauthenticated access:
class MainActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
auth = FirebaseAuth.getInstance()
val email = auth.currentUser?.email ?: "Unknown"
binding.tvWelcome.text = "Welcome, $email"
binding.btnLogout.setOnClickListener {
auth.signOut()
startActivity(Intent(this, LoginActivity::class.java))
finish()
}
}
override fun onStart() {
super.onStart()
if (auth.currentUser == null) {
startActivity(Intent(this, LoginActivity::class.java))
finish()
}
}
}Validating password consistency before initiating remote Firebase authentication tasks:
private fun register() {
val email = binding.etEmail.text.toString()
val password = binding.etPassword.text.toString()
val confirmPassword = binding.etConfirm.text.toString()
if (email.isEmpty() || password.isEmpty() || confirmPassword.isEmpty()) {
Toast.makeText(this, "Please enter all fields", Toast.LENGTH_SHORT).show()
return
}
if (password != confirmPassword) {
Toast.makeText(this, "Passwords do not match", Toast.LENGTH_SHORT).show()
return
}
auth.createUserWithEmailAndPassword(email, password).addOnCompleteListener { task ->
if (task.isSuccessful) {
Toast.makeText(this, "Registration successful", Toast.LENGTH_SHORT).show()
startActivity(Intent(this, MainActivity::class.java))
finish()
} else {
Toast.makeText(this, "Registration failed", Toast.LENGTH_SHORT).show()
}
}
}Firebase-Auth-Basic-Setup/
├── app/
│ ├── src/main/java/com/shayan/firebaseauthsetup/
│ │ ├── LoginActivity.kt # Login screen & auto-redirect logic
│ │ ├── RegisterActivity.kt # Account creation & password validation
│ │ └── MainActivity.kt # Protected dashboard with sign-out handler
│ ├── src/main/res/
│ │ ├── layout/ # XML layouts for Login, Register, Main
│ │ └── values/ # Color palettes, string resources & themes
│ ├── build.gradle.kts # Target SDK 36, Firebase Auth & Firestore dependencies
│ └── google-services.json # (Template) Firebase configuration file
└── gradle/
└── libs.versions.toml # Centralized dependency catalog
| Layer | Technology | Details |
|---|---|---|
| Platform | Android | API 24+ (Compile & Target SDK 36) |
| Language | Kotlin | 2.0+ |
| Authentication | Firebase Auth | com.google.firebase:firebase-auth |
| Database Readiness | Cloud Firestore | com.google.firebase:firebase-firestore |
| Google Services | Google Services Plugin | com.google.gms.google-services |
| UI Framework | Android XML + ViewBinding | Null-safe view referencing |
| Design | Material Design Components | com.google.android.material:material |
- Android Studio Ladybug (2024.2.1+) or newer.
- JDK 11 or JDK 17.
- A Google Firebase Project:
- Go to the Firebase Console.
- Create a new project and add an Android app with package name
com.shayan.firebaseauthsetup. - Enable Email/Password sign-in method in Firebase Console under Authentication > Sign-in method.
- Download
google-services.jsonand place it in theapp/root directory.
- Clone the repository:
git clone https://github.com/shayann07/Firebase-Auth-Basic-Setup.git cd Firebase-Auth-Basic-Setup - Add
google-services.json: Place your Firebase credentials file in theapp/directory. - Build and install:
./gradlew assembleDebug
- Deploy: Run on an Android emulator or physical device.
This project is licensed under the MIT License — Copyright (c) 2026 shayann07.