Skip to content

Commit

Permalink
#12 Google SignIn 성공 - 토큰 받기 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
comye1 committed Feb 28, 2022
1 parent 4e7f4d7 commit 3876b38
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ fun SignInScreen(
) {
val scope = rememberCoroutineScope()

val signInRequestCode = 1
val launcher =
rememberLauncherForActivityResult(contract = ActivityResultContracts.StartActivityForResult()) {
val task = GoogleSignIn.getSignedInAccountFromIntent(it.data)
Expand All @@ -56,6 +55,7 @@ fun SignInScreen(
val account = task.getResult(ApiException::class.java)!!
scope.launch {
viewModel.googleSignIn(account.idToken ?: "null")
toMain()
}
} catch (e: ApiException) {
scope.launch {
Expand All @@ -65,25 +65,6 @@ fun SignInScreen(
}
}

// val authResultLauncher =
// rememberLauncherForActivityResult(contract = GoogleAuthResultContract()) { task ->
// try {
// val account = task.getResult(ApiException::class.java)!!
// Log.d("google", "task : $task")
// if (account == null) {
// Log.d("google", "null")
// viewModel.oAuthFailed()
// } else {
// viewModel.googleSignIn(account.idToken!!)
//// account.email
//// account.displayName
// }
// } catch (e: ApiException) {
// viewModel.oAuthFailed()
// Log.d("google", "exception ${e.message!!}")
// }
// }

Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
Expand Down Expand Up @@ -124,19 +105,7 @@ fun SignInScreen(
size = 24.dp,
text = "Sign in with Google"
) {
// Log.d("google provider", FirebaseAuthProvider.PROVIDER_ID)
//
// val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
// .requestIdToken(R.string.web_client_id.toString())
// .requestEmail()
// .build()
//
// val googleSignInClient = GoogleSignIn.getClient(context, gso)
launcher.launch(getGoogleSignInClient(context).signInIntent)

// authResultLauncher.launch(signInRequestCode)
// val intent = getGoogleSignInClient(context).signInIntent
// handleSignInResult(GoogleSignIn.getSignedInAccountFromIntent(intent))
}
Spacer(modifier = Modifier.height(16.dp))
OAuthSignInButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,8 @@ class SignInViewModel @Inject constructor(
}
}

fun googleSignIn(accessToken: String) {
Log.d("signup google", accessToken)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import com.comye1.dontsleepdriver.R
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.Scopes
import com.google.android.gms.common.api.Scope

fun getGoogleSignInClient(context: Context): GoogleSignInClient {
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Scope(Scopes.PLUS_LOGIN))
.requestScopes(Scope(Scopes.PLUS_ME))
.requestEmail()
.requestIdToken(context.getString(R.string.web_client_id))
.build()
Expand Down

0 comments on commit 3876b38

Please sign in to comment.