![](/img/trans.png)
[英]Jetpack Compose Firebase Signin With Google, no error but not working, what am I missing
[英]Google authentication with Firebase and Jetpack Compose
我正在使用 Kotlin、Android Studio 和 Jetpack Compose
我想做的事:
單擊按鈕后,我想使用谷歌身份驗證和 firebase 注冊用戶
我試圖做的事情:
我試圖遵循Firebase Auth Documentation ,但它真的很難理解,因為它經常讓我回到Google Documentation ,這對 Jetpack Compose 也沒有幫助。
我找不到任何解釋此實現的最新視頻或指南。 如果有人可以解釋如何開始,那就太棒了。
val context = LocalContext.current
val token = stringResource(R.string.default_web_client_id)
val launcherNav = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) {
navController.navigate(Screen.MainScreen.route)
}
val launcher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
) {
val task =
try {
val account = GoogleSignIn.getSignedInAccountFromIntent(it.data)
.getResult(ApiException::class.java)
val credential = GoogleAuthProvider.getCredential(account.idToken!!, null)
FirebaseAuth.getInstance().signInWithCredential(credential)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
}
}
}
catch (e: ApiException) {
Log.w("TAG", "GoogleSign in Failed", e)
}
}
Button(
onClick = {
val gso = GoogleSignInOptions
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(token)
.requestEmail()
.build()
val googleSignInClient = GoogleSignIn.getClient(context, gso)
launcher.launch(googleSignInClient.signInIntent)
}
) {
Text(text = "Sign In")
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.