Skip to content

Commit

Permalink
feat(#174): TokenAuthenticator 에 logoutEventRepository 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
yang1318 committed Dec 6, 2023
1 parent ecaea54 commit 90dcad4
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package boostcamp.and07.mindsync.data.network

import boostcamp.and07.mindsync.data.network.request.NewAccessTokenRequest
import boostcamp.and07.mindsync.data.repository.login.DataStoreConst
import boostcamp.and07.mindsync.data.repository.login.LogoutEventRepository
import boostcamp.and07.mindsync.data.repository.login.TokenRepository
import boostcamp.and07.mindsync.ui.util.NetworkExceptionMessage
import com.kakao.sdk.common.Constants.AUTHORIZATION
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import okhttp3.Authenticator
import okhttp3.Request
Expand All @@ -17,15 +21,17 @@ class TokenAuthenticator
@Inject
constructor(
private val tokenRepository: TokenRepository,
private val logoutEventRepository: LogoutEventRepository,
private val tokenApi: TokenApi,
) : Authenticator {
override fun authenticate(
route: Route?,
response: Response,
): Request? {
if (response.message == DataStoreConst.REFRESH_TOKEN_EXPIRED) {
// TODO : Refresh 토큰 만료 => 로그인 화면으로 이동
response.close()
CoroutineScope(Dispatchers.IO).launch {
logoutEventRepository.logoutRequest()
}
return null
}
// 무조건 토큰을 받아온 후 진행시키기 위해 runBlocking
Expand All @@ -39,8 +45,9 @@ class TokenAuthenticator
}

if (refreshToken == null || accessToken == null) {
// TODO : Refresh 토큰 만료 => 로그인 화면으로 이동
response.close()
CoroutineScope(Dispatchers.IO).launch {
logoutEventRepository.logoutRequest()
}
return null
}
// 무조건 새 토큰을 받아온 후 진행시키기 위해 runBlocking
Expand Down

0 comments on commit 90dcad4

Please sign in to comment.