GitLiveApp / firebase-kotlin-sdk

A Kotlin-first SDK for Firebase
https://gitliveapp.github.io/firebase-kotlin-sdk/
Apache License 2.0
1.15k stars 156 forks source link

App initialization issue for KMM on web/js #465

Closed danzakusilo closed 8 months ago

danzakusilo commented 9 months ago

I am targeting Android and Web/JS with compose multiplatform.

Android runs just fine, but when I try to run the web page with wasm, i get the FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() error. I am using Wasm to run the web page, if it's incompatible with this SDK, I would appreciate if anyone provided alternative methods to run kotlinJS. Thanks!

Here's the relevant code in commonMain package:

import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.auth.auth
import org.koin.core.component.KoinComponent

class LoginApi : KoinComponent {
    val auth = Firebase.auth

    suspend fun registration(email: String, password: String): String{
        val user = auth.createUserWithEmailAndPassword(email, password)
        return user.user?.uid.toString()
    }
}

in jsMain package, loginScreen just call the LoginViewModel and it's only method: (this also uses webpack)


@OptIn(ExperimentalComposeUiApi::class)
fun main() {
    onWasmReady {
        CanvasBasedWindow("FamilyApp") {
            LoginScreen()
        }
    }
}
nbransby commented 8 months ago

closing as dup of https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/440