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 9740861..635d07f 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 8e4e324..f4316cc 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 47244ec..fb2e91a 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() diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/MyPageRepositoryImpl.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/MyPageRepositoryImpl.kt index 5053c56..8966e55 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/MyPageRepositoryImpl.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/MyPageRepositoryImpl.kt @@ -8,6 +8,8 @@ import com.avengers.nibobnebob.data.model.response.MyDefaultInfoResponse import com.avengers.nibobnebob.data.model.response.MyInfoResponse import com.avengers.nibobnebob.data.model.runRemote import com.avengers.nibobnebob.data.remote.MyPageApi +import com.navercorp.nid.oauth.NidOAuthLogin +import com.navercorp.nid.oauth.OAuthLoginCallback import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import javax.inject.Inject @@ -43,6 +45,15 @@ class MyPageRepositoryImpl @Inject constructor( is BaseState.Success -> { dataStoreManager.deleteAccessToken() dataStoreManager.deleteRefreshToken() + + NidOAuthLogin().callDeleteTokenApi(object : OAuthLoginCallback{ + override fun onError(errorCode: Int, message: String) {} + + override fun onFailure(httpStatus: Int, message: String) {} + + override fun onSuccess() {} + }) + emit(result) } diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/MyPageFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/MyPageFragment.kt index 55926df..b2755b7 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/MyPageFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/MyPageFragment.kt @@ -52,8 +52,8 @@ class MyPageFragment : BaseFragment(R.layout.fragment_my_ viewModel.events.collect { event -> when (event) { is MyEditPageEvent.NavigateToIntro -> { - (activity as MainActivity).finish() val intent = Intent(context, IntroActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(intent) } } @@ -76,7 +76,6 @@ class MyPageFragment : BaseFragment(R.layout.fragment_my_ } private fun withDrawConfirm() { - Log.d("TEST", "탈퇴 완료") viewModel.withdraw() }