https://kotlinlang.org logo
#compose
Title
# compose
j

Jason Inbody

08/20/2021, 11:16 PM
Is there any example code on how to use the google sign in button in jetpack compose? Or do I need to wrap the google sign in button in an android view?
Copy code
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestEmail()
    .build()
val mGoogleSignInClient = GoogleSignIn.getClient(user.context, gso)
val signInIntent = mGoogleSignInClient.signInIntent
val googleSignInLauncher = rememberLauncherForActivityResult(
    contract = ActivityResultContracts.StartActivityForResult()
){ result: ActivityResult ->
    if (result.resultCode == Activity.RESULT_OK) {
        //  you will get result here in result.data
        val task: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(result.data)
        print("hello")
    }else{
        user.openErrorDialog("Google Sign In Failure", "Failed to sign in with Google")
    }
}
then launch with
Copy code
googleSignInLauncher.launch(googleSignInIntent)
worked for me