Skip to content

Commit 9b4a2c1

Browse files
committed
fix: TokenAuthenticator 임계 구역 재설정
1 parent 033353c commit 9b4a2c1

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

core/network/src/main/java/com/suwiki/core/network/authenticator/TokenAuthenticator.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ internal class TokenAuthenticator @Inject constructor(
2121
override fun authenticate(route: Route?, response: okhttp3.Response): Request? = runBlocking {
2222
if (response.isTokenExpired.not()) return@runBlocking null
2323

24-
val accessToken = authRepository.accessToken.first()
25-
val alreadyRefreshed = response.request.header(AUTH_HEADER)?.contains(accessToken) == false
26-
// if request's header's token is different, then that means the access token has already been refreshed
27-
// we return the response with the locally persisted token in the header
28-
if (alreadyRefreshed) {
29-
return@runBlocking response.request.newBuilder()
30-
.header(AUTH_HEADER, accessToken)
31-
.build()
32-
}
24+
mutex.withLock {
25+
val accessToken = authRepository.accessToken.first()
26+
val alreadyRefreshed = response.request.header(AUTH_HEADER)?.contains(accessToken) == false
27+
// if request's header's token is different, then that means the access token has already been refreshed
28+
// we return the response with the locally persisted token in the header
29+
if (alreadyRefreshed) {
30+
Timber.tag(RETROFIT_TAG).d("TokenAuthenticator - 이미 토큰이 갱신됨 / 중단된 API 재요청")
3331

32+
return@runBlocking response.request.newBuilder()
33+
.header(AUTH_HEADER, accessToken)
34+
.build()
35+
}
3436

35-
Timber.tag(RETROFIT_TAG).d("TokenAuthenticator - authenticate() called / 토큰 만료. 토큰 Refresh 요청")
36-
mutex.withLock {
3737
if (authRepository.reissueRefreshToken()) {
38-
Timber.tag(RETROFIT_TAG).d("TokenAuthenticator - authenticate() called / 중단된 API 재요청")
38+
Timber.tag(RETROFIT_TAG).d("TokenAuthenticator - 토큰 갱신 성공 / 중단된 API 재요청")
3939
response.request
4040
.newBuilder()
4141
.removeHeader(AUTH_HEADER)

0 commit comments

Comments
 (0)