From 90dcad4c17327a549a92b7217374c6bef70b912b Mon Sep 17 00:00:00 2001 From: "seona.Yang" <75965560+yang1318@users.noreply.github.com> Date: Wed, 6 Dec 2023 01:29:45 +0900 Subject: [PATCH] =?UTF-8?q?feat(#174):=20TokenAuthenticator=20=EC=97=90=20?= =?UTF-8?q?logoutEventRepository=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mindsync/data/network/TokenAuthenticator.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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