
Unified, type-safe Firebase Authentication: email/password, Google/Apple/Facebook and anonymous sign-ins; flow-based real-time auth state, sealed-result types, testable fake backend, zero-config initialization.
A complete Firebase Authentication solution for Android, iOS, and Desktop
with a unified, type-safe API. Zero-config on Android, one-line setup on iOS!
๐ฆ Installation โข ๐ Docs โข ๐ฏ Examples โข โญ Star Us!
โก Super fast? See QUICKSTART.md (30 seconds)
๐ Detailed setup: See below (2 minutes)
kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.com3run:firebase-auth-kmp:1.0.3")
}
}
}For JitPack, if you have a jvm("desktop") target, use platform-specific dependencies:
repositories {
maven("https://jitpack.io")
}
kotlin {
sourceSets {
androidMain.dependencies {
implementation("com.github.com3run.firebase-auth-kmp:firebase-auth-kmp-android:v1.0.3")
}
iosMain.dependencies {
implementation("com.github.com3run.firebase-auth-kmp:firebase-auth-kmp-iosarm64:v1.0.3")
}
val desktopMain by getting {
dependencies {
implementation("com.github.com3run.firebase-auth-kmp:firebase-auth-kmp-jvm:v1.0.3")
}
}
}
}Note: JitPack requires platform-specific artifacts for
desktopMainsource sets. For automatic resolution, use Maven Central instead.
No code needed! Just add your google-services.json file.
โ OLD: You had to manually set
โ
NEW: Auto-initializes via ContentProvider!ActivityHolder.current
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// That's it! No Firebase Auth initialization needed! ๐
setContent {
App()
}
}
}FirebaseAuthBridge.swift from the library to your iOS appimport FirebaseCore
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
FirebaseAuthBridge.shared.start() // โ ONE LINE!
return true
}
}Create firebase-config.json in your project root:
{
"apiKey": "YOUR_FIREBASE_API_KEY",
"projectId": "your-project-id"
}Find your API key in Firebase Console โ
๐ฏ Want detailed setup? See EASY-INTEGRATION.md
import dev.com3run.firebaseauthkmp.*
import org.koin.core.context.startKoin
// Initialize Koin
startKoin {
modules(module {
single<AuthBackend> { platformAuthBackend() }
single { AuthRepository(get()) }
})
}
// Use auth repository
val authRepository = get<AuthRepository>()
// Monitor auth state
authRepository.authState.collect { user ->
if (user != null) {
println("Signed in: ${user.email}")
} else {
println("Signed out")
}
}val result = authRepository.signInWithEmailAndPassword(
email = "user@example.com",
password = "password123"
)
when (result) {
is AuthResult.Success -> println("Welcome ${result.data.displayName}!")
is AuthResult.Failure -> when (result.error) {
AuthError.InvalidCredential -> println("Wrong email or password")
AuthError.UserNotFound -> println("No account found")
else -> println("Error: ${result.error}")
}
}// Request ID token (platform-specific UI flow)
val idToken = requestGoogleIdToken()
if (idToken != null) {
val result = authRepository.signInWithGoogle(idToken)
when (result) {
is AuthResult.Success -> println("Google sign-in successful!")
is AuthResult.Failure -> println("Error: ${result.error}")
}
}val result = authRepository.signInAnonymously()
when (result) {
is AuthResult.Success -> println("Signed in as guest!")
is AuthResult.Failure -> println("Error: ${result.error}")
}authRepository.signOut()The library follows clean architecture principles:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AuthRepository โ โ Validation + High-level API
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AuthBackend (Interface) โ โ Platform-agnostic contract
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโดโโโโโโโโโฌโโโโโโโโโโโโโโ
โผ โผ โผ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ Android โ โ iOS โ โ Desktop โ
โ Firebase โ โ Firebase โ โ Firebase โ
โ SDK โ โ Bridge โ โ REST API โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
| Platform | Implementation | Features |
|---|---|---|
| Android | Native Firebase SDK | โ Auto-init, Full OAuth, Offline support |
| iOS | Notification bridge | โ Native SDK, Full OAuth, One-line setup |
| Desktop | REST API | โ Email/Password, Anonymous, Manual OAuth |
The library includes FakeAuthBackend for unit testing:
import dev.com3run.firebaseauthkmp.FakeAuthBackend
import dev.com3run.firebaseauthkmp.AuthRepository
@Test
fun `test sign in success`() = runTest {
val fakeBackend = FakeAuthBackend()
val authRepository = AuthRepository(fakeBackend)
fakeBackend.setAuthResult(AuthResult.Success(testUser))
val result = authRepository.signInWithEmailAndPassword("test@example.com", "password")
assertTrue(result is AuthResult.Success)
}This repository includes a complete sample app demonstrating all authentication methods:
Run the composeApp module to see it in action!
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Created by Kamran Mammadov
Special thanks to all contributors!
Made with โค๏ธ using Kotlin Multiplatform
โญ If you find this library helpful, please star the repo!
A complete Firebase Authentication solution for Android, iOS, and Desktop
with a unified, type-safe API. Zero-config on Android, one-line setup on iOS!
๐ฆ Installation โข ๐ Docs โข ๐ฏ Examples โข โญ Star Us!
โก Super fast? See QUICKSTART.md (30 seconds)
๐ Detailed setup: See below (2 minutes)
kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.com3run:firebase-auth-kmp:1.0.3")
}
}
}For JitPack, if you have a jvm("desktop") target, use platform-specific dependencies:
repositories {
maven("https://jitpack.io")
}
kotlin {
sourceSets {
androidMain.dependencies {
implementation("com.github.com3run.firebase-auth-kmp:firebase-auth-kmp-android:v1.0.3")
}
iosMain.dependencies {
implementation("com.github.com3run.firebase-auth-kmp:firebase-auth-kmp-iosarm64:v1.0.3")
}
val desktopMain by getting {
dependencies {
implementation("com.github.com3run.firebase-auth-kmp:firebase-auth-kmp-jvm:v1.0.3")
}
}
}
}Note: JitPack requires platform-specific artifacts for
desktopMainsource sets. For automatic resolution, use Maven Central instead.
No code needed! Just add your google-services.json file.
โ OLD: You had to manually set
โ
NEW: Auto-initializes via ContentProvider!ActivityHolder.current
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// That's it! No Firebase Auth initialization needed! ๐
setContent {
App()
}
}
}FirebaseAuthBridge.swift from the library to your iOS appimport FirebaseCore
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
FirebaseAuthBridge.shared.start() // โ ONE LINE!
return true
}
}Create firebase-config.json in your project root:
{
"apiKey": "YOUR_FIREBASE_API_KEY",
"projectId": "your-project-id"
}Find your API key in Firebase Console โ
๐ฏ Want detailed setup? See EASY-INTEGRATION.md
import dev.com3run.firebaseauthkmp.*
import org.koin.core.context.startKoin
// Initialize Koin
startKoin {
modules(module {
single<AuthBackend> { platformAuthBackend() }
single { AuthRepository(get()) }
})
}
// Use auth repository
val authRepository = get<AuthRepository>()
// Monitor auth state
authRepository.authState.collect { user ->
if (user != null) {
println("Signed in: ${user.email}")
} else {
println("Signed out")
}
}val result = authRepository.signInWithEmailAndPassword(
email = "user@example.com",
password = "password123"
)
when (result) {
is AuthResult.Success -> println("Welcome ${result.data.displayName}!")
is AuthResult.Failure -> when (result.error) {
AuthError.InvalidCredential -> println("Wrong email or password")
AuthError.UserNotFound -> println("No account found")
else -> println("Error: ${result.error}")
}
}// Request ID token (platform-specific UI flow)
val idToken = requestGoogleIdToken()
if (idToken != null) {
val result = authRepository.signInWithGoogle(idToken)
when (result) {
is AuthResult.Success -> println("Google sign-in successful!")
is AuthResult.Failure -> println("Error: ${result.error}")
}
}val result = authRepository.signInAnonymously()
when (result) {
is AuthResult.Success -> println("Signed in as guest!")
is AuthResult.Failure -> println("Error: ${result.error}")
}authRepository.signOut()The library follows clean architecture principles:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AuthRepository โ โ Validation + High-level API
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AuthBackend (Interface) โ โ Platform-agnostic contract
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโดโโโโโโโโโฌโโโโโโโโโโโโโโ
โผ โผ โผ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ Android โ โ iOS โ โ Desktop โ
โ Firebase โ โ Firebase โ โ Firebase โ
โ SDK โ โ Bridge โ โ REST API โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
| Platform | Implementation | Features |
|---|---|---|
| Android | Native Firebase SDK | โ Auto-init, Full OAuth, Offline support |
| iOS | Notification bridge | โ Native SDK, Full OAuth, One-line setup |
| Desktop | REST API | โ Email/Password, Anonymous, Manual OAuth |
The library includes FakeAuthBackend for unit testing:
import dev.com3run.firebaseauthkmp.FakeAuthBackend
import dev.com3run.firebaseauthkmp.AuthRepository
@Test
fun `test sign in success`() = runTest {
val fakeBackend = FakeAuthBackend()
val authRepository = AuthRepository(fakeBackend)
fakeBackend.setAuthResult(AuthResult.Success(testUser))
val result = authRepository.signInWithEmailAndPassword("test@example.com", "password")
assertTrue(result is AuthResult.Success)
}This repository includes a complete sample app demonstrating all authentication methods:
Run the composeApp module to see it in action!
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Created by Kamran Mammadov
Special thanks to all contributors!
Made with โค๏ธ using Kotlin Multiplatform
โญ If you find this library helpful, please star the repo!