Skip to content

Commit

Permalink
fix: 회원 탈퇴 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
re4rk committed Oct 7, 2023
1 parent 9ddfb40 commit 9b3c43c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AuthDefaultRepository @Inject constructor(

override suspend fun deleteAccount(): Result<Unit> = runCatchingResponse {
socialAuthRepository.deleteAccount()
tokenRetrofitService.deleteUserAccount()
tokenRetrofitService.deleteUserAccount("Bearer ${tokenLocalDataSource.token}")
}.onSuccessOrCatch {
tokenLocalDataSource.token = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.festago.festago.data.repository
import android.content.Context
import com.festago.festago.presentation.util.loginWithKakao
import com.festago.festago.repository.SocialAuthRepository
import com.kakao.sdk.auth.AuthApiClient
import com.kakao.sdk.auth.TokenManagerProvider
import com.kakao.sdk.user.UserApiClient
import dagger.hilt.android.qualifiers.ApplicationContext
Expand All @@ -13,27 +12,25 @@ import javax.inject.Inject
class SocialAuthKakaoRepository @Inject constructor(
@ApplicationContext private val context: Context,
) : SocialAuthRepository {

override val socialType: String = SOCIAL_TYPE_KAKAO

override suspend fun getSocialToken(): Result<String> = runCatching {
val oAuthToken = TokenManagerProvider.instance.manager.getToken()
val tokenManger = TokenManagerProvider.instance.manager
val oAuthToken = tokenManger.getToken()

when {
oAuthToken == null || oAuthToken.refreshTokenExpiresAt < Date() ->
UserApiClient.loginWithKakao(context)

oAuthToken.accessTokenExpiresAt < Date() -> {
AuthApiClient.instance.refreshToken { _, throwable ->
if (throwable != null) {
throw throwable
}
else -> {
UserApiClient.instance.accessTokenInfo { _, throwable ->
if (throwable != null) throw throwable
}
}
}

val accessToken = TokenManagerProvider.instance.manager.getToken()?.accessToken
?: throw Exception("Unknown error")
accessToken
tokenManger.getToken()?.accessToken ?: throw Exception("Unknown error")
}

override suspend fun signOut(): Result<Unit> {
Expand All @@ -42,8 +39,12 @@ class SocialAuthKakaoRepository @Inject constructor(
}

override suspend fun deleteAccount(): Result<Unit> {
UserApiClient.instance.unlink { error ->
if (error != null) throw error
synchronized(this) {
TokenManagerProvider.instance.manager.getToken()?.let {
UserApiClient.instance.unlink { error ->
if (error != null) throw error
}
}
}
return Result.success(Unit)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.festago.festago.data.dto.OauthTokenResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.Header
import retrofit2.http.POST

interface TokenRetrofitService {
Expand All @@ -15,5 +16,7 @@ interface TokenRetrofitService {
): Response<OauthTokenResponse>

@DELETE("/auth")
suspend fun deleteUserAccount(): Response<Unit>
suspend fun deleteUserAccount(
@Header("authorization") token: String,
): Response<Unit>
}

0 comments on commit 9b3c43c

Please sign in to comment.