Open omarzer0 opened 11 months ago
@omarzer0 were you able to solve this issue, I mean were you able to use moko-biometry while supporting desktop app?
Any update on this issue? tried to work around for many hours but ending up with "@Composable invocations can only happen from the context of a @Composable function" no matter what I do, either I support desktop app or biometry, not a great choice either way.
interface BiometryAuthenticator {
suspend fun checkBiometryAuthentication(
requestTitle: String,
requestReason: String,
failureButtonText: String,
allowDeviceCredentials: Boolean
): Boolean
}
expect class BiometryAuthenticatorFactory() {
@Composable
fun createBiometryAuthenticator(): BiometryAuthenticator
}
// AndroidBiometryAuthenticatorFactory.kt (androidMain)
package domain
import androidx.compose.runtime.Composable
import dev.icerock.moko.biometry.compose.rememberBiometryAuthenticatorFactory
import dev.icerock.moko.resources.desc.Raw
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.biometry.BiometryAuthenticator as MokoBiometryAuthenticator
actual class BiometryAuthenticatorFactory {
@Composable
actual fun createBiometryAuthenticator(): BiometryAuthenticator {
val factory = rememberBiometryAuthenticatorFactory()
return MokoBiometryAuthenticatorWrapper(factory.createBiometryAuthenticator())
}
private class MokoBiometryAuthenticatorWrapper(
private val authenticator: MokoBiometryAuthenticator
) : BiometryAuthenticator {
override suspend fun checkBiometryAuthentication(
requestTitle: String,
requestReason: String,
failureButtonText: String,
allowDeviceCredentials: Boolean
): Boolean {
return authenticator.checkBiometryAuthentication(
requestTitle = StringDesc.Raw(requestTitle),
requestReason = StringDesc.Raw(requestReason),
failureButtonText = StringDesc.Raw(failureButtonText),
allowDeviceCredentials = allowDeviceCredentials
)
}
}
}
@Composable
fun LoginScreen() {
val viewModel = getViewModel(
key = "biometry-screen",
factory = viewModelFactory {
AuthViewModel(
biometryAuthenticatorFactory.createBiometryAuthenticator() <-- It breaks here
)
}
) {
Column() {
BindBiometryAuthenticatorEffect(viewModel.biometryAuthenticator) <-- and here....
}
I was able to solve this issue with this work around. https://stackoverflow.com/questions/78659556/composable-invocations-can-only-happen-from-the-context-of-a-composable-functi/78665157#78665157b
At first thx for your awesome libraries and great effort.
I'm using Biometry Auth in my KMP app and worked fine until I added Desktop support. I get this error
I know that Desktop has no touch or face ID but is there a way to exclude JVM targets from using this library or we can provide a custom auth screen for Desktop with pin number or even let the user provides his own implementation for it when isBiometricAvailable returns false?