com3run/firebase-auth-kmp
๐ฅ Production-ready Firebase Authentication for Kotlin Multiplatform (Android, iOS, Desktop) - Zero-config, type-safe, with unified API
Firebase Auth KMP
๐ฅ Production-Ready Firebase Authentication for Kotlin Multiplatform ๐ฅ
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!
โจ Features
- ๐ฏ 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
๐ Quick Start
โก Super fast? See QUICKSTART.md (30 seconds)
๐ Detailed setup: See below (2 minutes)
Installation
From Maven Central (Recommended)
kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.com3run:firebase-auth-kmp:1.0.3")
}
}
}From JitPack (Alternative)
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.
Platform Setup
Android โ AUTOMATIC!
No code needed! Just add your google-services.json file.
โ OLD: You had to manually set ActivityHolder.current
โ
NEW: Auto-initializes via ContentProvider!
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// That's it! No Firebase Auth initialization needed! ๐
setContent {
App()
}
}
}iOS ๐ฑ ONE LINE!
- 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
}
}Desktop ๐ป SIMPLE CONFIG!
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
๐ก Usage
Basic Authentication
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")
}
}Sign In with Email/Password
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}")
}
}Sign In with Google
// 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}")
}
}Sign In Anonymously
val result = authRepository.signInAnonymously()
when (result) {
is AuthResult.Success -> println("Signed in as guest!")
is AuthResult.Failure -> println("Error: ${result.error}")
}Sign Out
authRepository.signOut()๐ Documentation
Getting Started
- ๐ Easy Integration Guide - 5-minute setup for all platforms
- ๐ Library Integration Guide - Detailed setup instructions
- ๐ Usage Examples - More code examples
Platform-Specific
- ๐ค Android Setup - Auto-initialization details
- ๐ iOS Setup - Bridge configuration
- ๐ป Desktop Setup - JVM configuration & limitations
Advanced
- ๐ง Troubleshooting - Common issues and solutions
- ๐๏ธ Architecture - Clean architecture design
- ๐จโ๐ป Coding Guidelines - Best practices
- ๐ Migration Guide - Upgrading from v1.0.0/1.0.1
๐๏ธ Architecture
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 โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
Key Components
- AuthRepository: High-level API with input validation
- AuthBackend: Platform-specific interface (Android/iOS/Desktop)
- AuthModels: Common data models (AuthUser, AuthResult, AuthError)
Platform Implementations
| 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 |
๐งช Testing
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)
}๐ฆ Sample App
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!
โ๏ธ Requirements
- Kotlin 2.0+
- Android API 24+ (Android 7.0)
- iOS 13.0+
- JVM 11+ (Desktop)
- Firebase project with Authentication enabled
๐ What's New in v1.0.3
- โจ 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
๐ค Contributing
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
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Links
- ๐ฆ Maven Central
- ๐ Full Documentation
- ๐ Report Issues
- โญ Star on GitHub
- ๐ฌ Discussions
๐จโ๐ป Credits
Created by Kamran Mammadov
Special thanks to all contributors!
Made with โค๏ธ using Kotlin Multiplatform
โญ If you find this library helpful, please star the repo!