Skip to content

Commit 4aa6b1e

Browse files
authored
Merge pull request #128 from JJUYAAA/#124-refactor_social_login
[Refactor] 소셜로그인, 회원가입 관련 오류 수정
2 parents 0c5d8c6 + e12595e commit 4aa6b1e

File tree

9 files changed

+20
-90
lines changed

9 files changed

+20
-90
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ local.properties
1616
.idea/deploymentTargetSelector.xml
1717
.idea/misc.xml
1818
.idea/gradle.xml
19-
.idea/appInsightsSettings.xml
19+
.idea/appInsightsSettings.xml
20+
/app/google-services.json

.idea/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ dependencies {
108108
//implementation ("androidx.datastore:datastore-preferences:1.1.1")
109109

110110
// 구글 로그인
111-
implementation(platform("com.google.firebase:firebase-bom:34.1.0"))
112-
implementation("com.google.firebase:firebase-auth")
113111
implementation("com.google.android.gms:play-services-auth:21.2.0")
112+
113+
implementation("androidx.credentials:credentials:1.2.2")
114+
implementation("androidx.credentials:credentials-play-services-auth:1.2.2")
115+
114116
}
115117

116118
kapt {

app/google-services.json

Lines changed: 0 additions & 71 deletions
This file was deleted.

app/src/main/java/com/texthip/thip/data/repository/AuthRepository.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.texthip.thip.data.repository
22

33
import android.content.Context
4-
import com.google.firebase.Firebase
5-
import com.google.firebase.auth.GoogleAuthProvider
6-
import com.google.firebase.auth.auth
74
import com.kakao.sdk.user.UserApiClient
85
import com.texthip.thip.data.model.auth.request.AuthRequest
96
import com.texthip.thip.data.model.auth.response.AuthResponse
107
import com.texthip.thip.data.model.base.handleBaseResponse
118
import com.texthip.thip.data.service.AuthService
129
import kotlinx.coroutines.CancellableContinuation
1310
import 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
1515
import javax.inject.Inject
1616
import javax.inject.Singleton
1717
import 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()

app/src/main/java/com/texthip/thip/ui/mypage/screen/MypageEditScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fun EditProfileContent(
114114
WarningTextField(
115115
containerColor = colors.DarkGrey02,
116116
value = uiState.nickname,
117-
onValueChange = onNicknameChange,
117+
onValueChange = { newNickname -> onNicknameChange(newNickname.lowercase()) },
118118
hint = stringResource(R.string.nickname_condition),
119119
showWarning = uiState.nicknameWarningMessageResId != null,
120120
showIcon = false,

app/src/main/java/com/texthip/thip/ui/mypage/viewmodel/MyPageViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class MyPageViewModel @Inject constructor(
7171
viewModelScope.launch {
7272
tokenManager.clearTokens()
7373
// 2. 카카오 SDK에서 로그아웃
74-
UserApiClient.instance.unlink { error ->
74+
UserApiClient.instance.logout { error ->
7575
if (error != null) {
7676
Log.e("MyPageViewModel", "카카오 로그아웃 실패", error)
7777
} else {

app/src/main/java/com/texthip/thip/ui/signin/screen/SignupNicknameScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fun SignupNicknameContent(
100100
WarningTextField(
101101
containerColor = colors.DarkGrey02,
102102
value = nickname,
103-
onValueChange = onNicknameChange,
103+
onValueChange = { newNickname -> onNicknameChange(newNickname.lowercase()) },//소문자로 즉시 변경
104104
hint = stringResource(R.string.nickname_condition),
105105
showWarning = warningMessageResId != null,
106106
showIcon = false,

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,6 @@
446446
<string name="api_genre_science_it" translatable="false">과학/IT</string>
447447

448448
<!-- Google login constants -->
449-
<string name="default_web_client_id" translatable="false">353417813537-ck9g1v0qprlb5nf4dvasinim403eng0f.apps.googleusercontent.com</string>
449+
<string name="default_web_client_id" translatable="false">211189590640-a2ul4bnsvislm12ov7k8eu61mtketl8d.apps.googleusercontent.com</string>
450450

451451
</resources>

0 commit comments

Comments
 (0)