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!
- π― Cross-platform: Single codebase for Android, iOS & Desktop (JVM)
- π Easy Integration: Auto-initialization on Android, one-line setup on iOS
- π Complete Authentication:
- Email/Password (Sign up & Sign in)
- Google Sign-In
- Apple Sign-In (iOS)
- Anonymous Authentication
- Facebook Sign-In
- π Real-time Auth State: Flow-based auth state monitoring
- π‘οΈ Type-safe: Kotlin-first API with sealed classes for results
- π§ͺ Testable: Includes FakeAuthBackend for unit testing
- π± Platform-optimized: Native Firebase SDKs on Android/iOS, REST API on Desktop
- π Production-ready: Published on Maven Central
β‘ 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()
}
}
}- Copy
FirebaseAuthBridge.swiftfrom the library to your iOS app - Add to AppDelegate:
import 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()- π Easy Integration Guide - 5-minute setup for all platforms
- π Library Integration Guide - Detailed setup instructions
- π Usage Examples - More code examples
- π€ Android Setup - Auto-initialization details
- π iOS Setup - Bridge configuration
- π» Desktop Setup - JVM configuration & limitations
- π§ Troubleshooting - Common issues and solutions
- ποΈ Architecture - Clean architecture design
- π¨βπ» Coding Guidelines - Best practices
- π Migration Guide - Upgrading from v1.0.0/1.0.1
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 β
ββββββββββββββββ βββββββββββββββ ββββββββββββββββ
- AuthRepository: High-level API with input validation
- AuthBackend: Platform-specific interface (Android/iOS/Desktop)
- AuthModels: Common data models (AuthUser, AuthResult, AuthError)
| 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:
- β Email/Password authentication
- β Google Sign-In
- β Apple Sign-In (iOS)
- β Anonymous authentication
- β Profile management
- β Password reset
Run the composeApp module to see it in action!
- Kotlin 2.0+
- Android API 24+ (Android 7.0)
- iOS 13.0+
- JVM 11+ (Desktop)
- Firebase project with Authentication enabled
- β¨ Desktop/JVM support - Run on Windows, macOS, Linux
- π Android auto-initialization - Zero manual setup required!
- π± Simplified iOS setup - Ready-to-use bridge template
- π Easy Integration Guide - Get started in 2 minutes
- π§ Better error messages - Clear, actionable feedback
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- π¦ Maven Central
- π Full Documentation
- π Report Issues
- β Star on GitHub
- π¬ Discussions
Created by Kamran Mammadov
Special thanks to all contributors!
Made with β€οΈ using Kotlin Multiplatform
β If you find this library helpful, please star the repo!