11package com.texthip.thip.data.repository
22
33import android.content.Context
4- import com.google.firebase.Firebase
5- import com.google.firebase.auth.GoogleAuthProvider
6- import com.google.firebase.auth.auth
74import com.kakao.sdk.user.UserApiClient
85import com.texthip.thip.data.model.auth.request.AuthRequest
96import com.texthip.thip.data.model.auth.response.AuthResponse
107import com.texthip.thip.data.model.base.handleBaseResponse
118import com.texthip.thip.data.service.AuthService
129import kotlinx.coroutines.CancellableContinuation
1310import kotlinx.coroutines.suspendCancellableCoroutine
14- import kotlinx.coroutines.tasks.await
11+ import kotlinx.serialization.json.Json
12+ import kotlinx.serialization.json.jsonObject
13+ import kotlinx.serialization.json.jsonPrimitive
14+ import java.util.Base64
1515import javax.inject.Inject
1616import javax.inject.Singleton
1717import kotlin.coroutines.resume
@@ -36,13 +36,14 @@ class AuthRepository @Inject constructor(
3636 }
3737 suspend fun loginWithGoogle (idToken : String ): Result <AuthResponse ?> {
3838 return runCatching {
39- // Firebase에 구글 ID 토큰으로 로그인
40- val credential = GoogleAuthProvider .getCredential(idToken, null )
41- val authResult = Firebase .auth.signInWithCredential(credential).await()
42- val googleUid = authResult.user?.uid ? : throw IllegalStateException (" Google User UID is null" )
39+ val payload = idToken.split(' .' )[1 ]// ID 토큰을 .기준 분리
40+ val decodedJson = String (Base64 .getUrlDecoder().decode(payload))// 디코딩 해서 JSON 문자열 반환
41+
42+ val jsonObject = Json .parseToJsonElement(decodedJson).jsonObject
43+ val googleSubId = jsonObject[" sub" ]?.jsonPrimitive?.content ? : throw IllegalStateException (" 구글 userID (sub)값이 없습니다." )// sub 값 추출
4344
4445 // 받아온 UID로 신규/기존 유저인지 확인 요청
45- val request = AuthRequest (oauth2Id = " google_$googleUid " )
46+ val request = AuthRequest (oauth2Id = " google_$googleSubId " )
4647 authService.checkNewUser(request)
4748 .handleBaseResponse()
4849 .getOrThrow()
0 commit comments