I have a project which uses Firebase Authentication in Android. It works well and I want to port the same project to an iOS App using code sharing with Kotlin Multiplatform.
I initially thought I could simple create a
expect class FirebaseAuth
and
//AndroidMain
actual class FirebaseAuth
//iOSMain
actual class FirebaseAuth
But I don't really know how I could use the iOS version of FirebaseAuth in iOSMain? Can someone guide me here?
From now on there is a new official library about Kotlin Multiplatform firebase products. Supported platforms are Android, iOS and JavaScript.
https://firebaseopensource.com/projects/gitliveapp/firebase-kotlin-sdk/
Note: This is an old answer. Check out https://github.com/gitliveapp/firebase-kotlin-sdk/ for a reasonably maintained library.
I gave a talk on libraries for KMP and specifically built a wrapper around Firestore to go along with it.
https://github.com/touchlab/FirestoreKMP
https://vimeo.com/371460823
In that library I create extension functions to implement features. Your question is kind of broad, but I'd probably start with:
//common
expect fun FirebaseAuth.signIn(email:String, password:String):Task<AuthDataResult>
//ios main
actual fun FirebaseAuth.signIn(email:String, password:String):Task<AuthDataResult> = signInWithEmail(email, password) //Figure out async return value
The async return stuff can be a little tricky, but the firestore code will have examples. One here:
https://github.com/touchlab/FirestoreKMP/blob/master/firestore/src/commonMain/kotlin/co/touchlab/firebase/firestore/Query.kt#L17
I am building and publishing Firebase Wrappers for Kotlin Multiplatform!
Keep in mind that only common API between JS, JVM and iOS are available.
Here it is: https://github.com/lamba92/firebase-multiplatform
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With