From 2a11fbce60b3aeecf2c9c3ed3c2ee3a1678ddaae Mon Sep 17 00:00:00 2001 From: young Date: Sat, 25 Nov 2023 21:33:14 +0900 Subject: [PATCH] =?UTF-8?q?#86=20feat=20:=20applicationContext=20=EB=A1=9C?= =?UTF-8?q?=20accessToken=20=EC=9E=AC=EB=B0=9C=EA=B8=89=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=8B=9C=20IntroActivity=20=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt | 6 ++++++ .../avengers/nibobnebob/config/AccessTokenInterceptor.kt | 5 +---- .../com/avengers/nibobnebob/config/BearerInterceptor.kt | 9 ++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt index 97408616..635d07f1 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt @@ -13,13 +13,19 @@ import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp class App : Application(){ + init { + instance = this + } + override fun onCreate() { super.onCreate() initializeNaverSDK() } companion object{ + lateinit var instance : App val Context.dataStore: DataStore by preferencesDataStore(name = APP_NAME) + fun getContext(): Context = instance.applicationContext } private fun initializeNaverSDK(){ diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/config/AccessTokenInterceptor.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/config/AccessTokenInterceptor.kt index 8e4e3243..f4316cc9 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/config/AccessTokenInterceptor.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/config/AccessTokenInterceptor.kt @@ -1,8 +1,6 @@ package com.avengers.nibobnebob.config -import android.util.Log import com.avengers.nibobnebob.app.DataStoreManager -import com.avengers.nibobnebob.presentation.util.Constants.ACCESS import com.avengers.nibobnebob.presentation.util.Constants.AUTHORIZATION import com.avengers.nibobnebob.presentation.util.Constants.BEARER import kotlinx.coroutines.flow.first @@ -18,11 +16,10 @@ class AccessTokenInterceptor @Inject constructor(private val dataStoreManager: D @Throws(IOException::class) override fun intercept(chain: Interceptor.Chain): Response { - // 동기가 아닌 비동기로 불러와야한다.. runBlocking말고 다른 방안에 대해 고민 val accessToken = runBlocking { dataStoreManager.getAccessToken().first() } - Log.d("토큰 테스트",accessToken.toString()) + val builder: Request.Builder = chain.request().newBuilder() accessToken?.takeIf { it.isNotEmpty() }?.let { builder.addHeader(AUTHORIZATION, "$BEARER $it") diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/config/BearerInterceptor.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/config/BearerInterceptor.kt index 47244ece..fb2e91a0 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/config/BearerInterceptor.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/config/BearerInterceptor.kt @@ -1,6 +1,8 @@ package com.avengers.nibobnebob.config +import android.content.Intent +import com.avengers.nibobnebob.app.App import com.avengers.nibobnebob.app.DataStoreManager import com.avengers.nibobnebob.data.model.BaseState import com.avengers.nibobnebob.data.model.request.RefreshTokenRequest @@ -8,6 +10,7 @@ import com.avengers.nibobnebob.data.model.response.BaseResponse import com.avengers.nibobnebob.data.model.response.NaverLoginResponse import com.avengers.nibobnebob.data.model.runRemote import com.avengers.nibobnebob.data.remote.RefreshApi +import com.avengers.nibobnebob.presentation.ui.intro.IntroActivity import com.avengers.nibobnebob.presentation.util.Constants import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking @@ -48,11 +51,15 @@ class BearerInterceptor @Inject constructor( else -> { dataStoreManager.deleteAccessToken() dataStoreManager.deleteRefreshToken() + + val intent = Intent(App.getContext(), IntroActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + App.getContext().startActivity(intent) } } } } - (newAccessToken)?.let { + newAccessToken?.let { val newRequest = originalRequest.newBuilder() .addHeader(AUTHORIZATION, "$BEARER $newAccessToken") .build()