extracy logout button to it's own comosable function

This commit is contained in:
Satindar Dhillon 2022-08-29 09:33:48 -07:00
parent 386a47b73b
commit be51a17315

View file

@ -20,8 +20,6 @@ import com.google.android.gms.auth.api.signin.GoogleSignInOptions
@Composable
fun HomeView(viewModel: LoginViewModel) {
val context = LocalContext.current
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
@ -31,18 +29,24 @@ fun HomeView(viewModel: LoginViewModel) {
.padding(horizontal = 6.dp)
) {
Text("You have a valid auth token. Nice. Go save something in Chrome!")
Button(onClick = {
// Sign out google users
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.build()
val googleSignIn = GoogleSignIn.getClient(context, signInOptions)
googleSignIn.signOut()
viewModel.logout()
}) {
Text(text = "Logout")
}
LogoutButton { viewModel.logout() }
}
}
@Composable
fun LogoutButton(actionHandler: () -> Unit) {
val context = LocalContext.current
Button(onClick = {
// Sign out google users
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.build()
val googleSignIn = GoogleSignIn.getClient(context, signInOptions)
googleSignIn.signOut()
actionHandler()
}) {
Text(text = "Logout")
}
}