Skip to content

Commit

Permalink
[feat/#122] 구글로그인 구현중..
Browse files Browse the repository at this point in the history
  • Loading branch information
SsongSik committed Aug 26, 2024
1 parent f0ed467 commit 88ed452
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dpm.spot"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
Expand Down
1 change: 1 addition & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
implementation(project(":core"))
implementation(project(":domain"))
implementation(project(":core:designsystem"))
implementation("com.google.android.gms:play-services-auth:20.1.0")
KotlinDependencies.run {
implementation(kotlin)
implementation(coroutines)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.dpm.presentation.login.ui

import android.content.Intent
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.compose.material.MaterialTheme
import androidx.lifecycle.asLiveData
Expand All @@ -15,7 +16,11 @@ import com.dpm.presentation.login.viewmodel.KakaoSignupViewModel
import com.dpm.presentation.login.viewmodel.LoginUiState
import com.dpm.presentation.scheme.SchemeKey
import com.dpm.presentation.scheme.viewmodel.SchemeState
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.api.ApiException
import com.google.android.gms.common.api.Scope
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
Expand All @@ -29,6 +34,26 @@ class KakaoSignupActivity : BaseActivity<FragmentKakaoSignupBinding>({
}) {
private val signUpViewModel by viewModels<KakaoSignupViewModel>()

private val googleSignInClient: GoogleSignInClient by lazy { onGoogleLogin() }
private val googleAuthLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
val task = GoogleSignIn.getSignedInAccountFromIntent(result.data)

try {
val account = task.getResult(ApiException::class.java)

val userName = account.givenName
val serverAuth = account.serverAuthCode
account.idToken
Intent(this, NicknameInputActivity::class.java).apply {
putExtra("kakaoToken", account.idToken)
startActivity(this)
}

} catch (e: ApiException) {
Timber.e(e)
}
}

private val callback: (OAuthToken?, Throwable?) -> Unit = { token, error ->
if (error != null) {
toast("카카오 로그인에 실패하였습니다.")
Expand All @@ -52,7 +77,7 @@ class KakaoSignupActivity : BaseActivity<FragmentKakaoSignupBinding>({
kakaoLoginCallBack()
},
onGoogleLoginClick = {
onGoogleLogin()
requestGoogleLogin()
}
)
}
Expand All @@ -77,8 +102,19 @@ class KakaoSignupActivity : BaseActivity<FragmentKakaoSignupBinding>({
}
}

private fun onGoogleLogin() {
//Todo GoogleLogin
private fun onGoogleLogin(): GoogleSignInClient {
val googleSignInOption = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestServerAuthCode("513574163474-0jmn0tks8hiolpl9r7gmc037n5mcg64t.apps.googleusercontent.com")
.requestEmail()
.build()

return GoogleSignIn.getClient(this, googleSignInOption)
}

private fun requestGoogleLogin() {
googleSignInClient.signOut()
val signInIntent = googleSignInClient.signInIntent
googleAuthLauncher.launch(signInIntent)
}

private fun initObservers() {
Expand Down

0 comments on commit 88ed452

Please sign in to comment.