GitHunt
CO

com3run/firebase-auth-kmp

๐Ÿ”ฅ Production-ready Firebase Authentication for Kotlin Multiplatform (Android, iOS, Desktop) - Zero-config, type-safe, with unified API

Firebase Auth KMP

Maven Central
GitHub Release
License
Kotlin

Android
iOS
Desktop
GitHub Stars

๐Ÿ”ฅ 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

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 desktopMain source 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!

  1. Copy FirebaseAuthBridge.swift from the library to your iOS app
  2. 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
    }
}

Get the bridge file โ†’

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

Platform-Specific

Advanced

๐Ÿ—๏ธ 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

See full changelog โ†’

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป 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!