From 9b4a2c1a486386de7f46cbd08e3dce2eebc7efbd Mon Sep 17 00:00:00 2001 From: jinukeu Date: Mon, 29 Jan 2024 11:05:29 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20TokenAuthenticator=20=EC=9E=84=EA=B3=84?= =?UTF-8?q?=20=EA=B5=AC=EC=97=AD=20=EC=9E=AC=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authenticator/TokenAuthenticator.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/network/src/main/java/com/suwiki/core/network/authenticator/TokenAuthenticator.kt b/core/network/src/main/java/com/suwiki/core/network/authenticator/TokenAuthenticator.kt index a4a05494..f8b23220 100644 --- a/core/network/src/main/java/com/suwiki/core/network/authenticator/TokenAuthenticator.kt +++ b/core/network/src/main/java/com/suwiki/core/network/authenticator/TokenAuthenticator.kt @@ -21,21 +21,21 @@ internal class TokenAuthenticator @Inject constructor( override fun authenticate(route: Route?, response: okhttp3.Response): Request? = runBlocking { if (response.isTokenExpired.not()) return@runBlocking null - val accessToken = authRepository.accessToken.first() - val alreadyRefreshed = response.request.header(AUTH_HEADER)?.contains(accessToken) == false - // if request's header's token is different, then that means the access token has already been refreshed - // we return the response with the locally persisted token in the header - if (alreadyRefreshed) { - return@runBlocking response.request.newBuilder() - .header(AUTH_HEADER, accessToken) - .build() - } + mutex.withLock { + val accessToken = authRepository.accessToken.first() + val alreadyRefreshed = response.request.header(AUTH_HEADER)?.contains(accessToken) == false + // if request's header's token is different, then that means the access token has already been refreshed + // we return the response with the locally persisted token in the header + if (alreadyRefreshed) { + Timber.tag(RETROFIT_TAG).d("TokenAuthenticator - 이미 토큰이 갱신됨 / 중단된 API 재요청") + return@runBlocking response.request.newBuilder() + .header(AUTH_HEADER, accessToken) + .build() + } - Timber.tag(RETROFIT_TAG).d("TokenAuthenticator - authenticate() called / 토큰 만료. 토큰 Refresh 요청") - mutex.withLock { if (authRepository.reissueRefreshToken()) { - Timber.tag(RETROFIT_TAG).d("TokenAuthenticator - authenticate() called / 중단된 API 재요청") + Timber.tag(RETROFIT_TAG).d("TokenAuthenticator - 토큰 갱신 성공 / 중단된 API 재요청") response.request .newBuilder() .removeHeader(AUTH_HEADER)