firebase-multiplatform icon indicating copy to clipboard operation
firebase-multiplatform copied to clipboard

Firebase wrappers for Kotlin Multiplatform Download Build Status

Kotlin Multiplatform is great, Firebase is great, why not use them togheter?

This library aims to bridge the common Firebase APIs in different platforms so that it is possible to use them in Kotlin Multiplatform!

All APIs look and feel will try to stay faithful to the Android version as much as possible since Kotlin has been created mostly with Java into account. As consequence of that, until a proper documentation is available use the official Firebase Android/Java documentation

How it works

Each class or interface has a platform specific delegate that is actually doing all the stuff inside the object. You can access this delegate only when ia a specific platform sources.

Platforms

Since Firebase has many platforms and services, covering them all by myself is kind of hard, especially for the Objective-C one. I will list the ones that i want to support by myself, but pull requests are welcome!

  • Android:
    • core ✅
    • auth ✅
    • storage ✅
      • storage-mobile [HALTED] #10
    • firestore [TODO]
  • JS web client:
    • core ✅ (probably bugged)
    • auth ✅ (probably bugged)
    • storage ✅ (probably bugged)
    • firestore [TODO]
  • iOS:
    • core ✅
    • auth ✅
    • storage ✅
      • storage-mobile [HALTED] #10
    • firestore [TODO]

Some examples

FirebaseApp initialization:

// common sources
val fApp: FirebaseApp = FirebaseApp.initializeApp {
    setApiKey("mkey")
    setApplicationId("mAppId")
    setDatabaseUrl("dbUrl")
    setProjectId("projectId")
    setStorageBucket("bucket")
    setGcmSenderId("i have no idea what this is")
}

FirebaseAuth initialization and auth changes:

// get the default firebase auth 
// instance and listen to auth changes
// in global scope
val job = FirebaseAuth.default.authStateFlow
    // this will be executed in main thread 
    // as the official documentation states!        
    .onEach { isLoggedIn -> /*do stuff*/ }
    .launchIn(GlobalScope)
    
    // stop listening and detach listener
    job.cancel()

Install Download

Packages are available at my Bintray repo:

repositories {
    maven("https://dl.bintray.com/lamba92/com.github.lamba92")
}

Someday I will setup the sign of the packes so that they will be mirrored to Maven Central Repository, but today is not that day!

Add in common sources:

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("com.github.lamba92:firebase-multiplatform-core:0.0.2")
                implementation("com.github.lamba92:firebase-multiplatform-auth:0.0.2")
            }
        }    
    }
}