I need to pass String token from FirebaseAppCheck to Kotlin Multiplatform.
I can get access to Kotlin class and assign values, but it always return null because of fact that Kotlin compiles first. Below is my swift function that should send token to KMM.
func sendAppCheckTokenToKMM() {
// Kotlin class
let factory = FirebaseAppCheckFactory()
AppCheck.appCheck().token(forcingRefresh: false) { token, error in
guard let token = token else {
print("Unable to retrieve App Check token.")
return
}
// Get the raw App Check token string.
let tokenString = token.token
factory.tokenId = tokenString
}
}
Next my kotlin FirebaseAppCheckFactory
looks like this.
class FirebaseAppCheckFactory {
lateinit var tokenId: String
fun isTokenInitialised() = ::tokenId.isInitialized
}
And last I need to send this token using suspended function in another class.
// FirebaseAppCheckService.kt
override suspend fun fetchToken(): String? {
if (firebaseAppCheckFactory.isTokenInitialised()){
return firebaseAppCheckFactory.tokenId
}
return null
}
Every time functions returns null. For now I cannot change fetchTokenFunction
.
Main class is expected/actual
to be using on Android and iOS as well. Implementation on Android is done, but on iOS I have to do this on platform first to initialize FirebaseAppCheck and then send app check token.
Is there another/better way to to this?