diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/data/network/TokenAuthenticator.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/data/network/TokenAuthenticator.kt index 237a46ff..5ab27950 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/data/network/TokenAuthenticator.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/data/network/TokenAuthenticator.kt @@ -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 @@ -17,6 +21,7 @@ class TokenAuthenticator @Inject constructor( private val tokenRepository: TokenRepository, + private val logoutEventRepository: LogoutEventRepository, private val tokenApi: TokenApi, ) : Authenticator { override fun authenticate( @@ -24,8 +29,9 @@ class TokenAuthenticator response: Response, ): Request? { if (response.message == DataStoreConst.REFRESH_TOKEN_EXPIRED) { - // TODO : Refresh 토큰 만료 => 로그인 화면으로 이동 - response.close() + CoroutineScope(Dispatchers.IO).launch { + logoutEventRepository.logoutRequest() + } return null } // 무조건 토큰을 받아온 후 진행시키기 위해 runBlocking @@ -39,8 +45,9 @@ class TokenAuthenticator } if (refreshToken == null || accessToken == null) { - // TODO : Refresh 토큰 만료 => 로그인 화면으로 이동 - response.close() + CoroutineScope(Dispatchers.IO).launch { + logoutEventRepository.logoutRequest() + } return null } // 무조건 새 토큰을 받아온 후 진행시키기 위해 runBlocking