diff --git a/core/network/src/main/java/org/sopt/network/authenticator/LinkMindAuthenticator.kt b/core/network/src/main/java/org/sopt/network/authenticator/LinkMindAuthenticator.kt index f90ded7e..54267ff0 100644 --- a/core/network/src/main/java/org/sopt/network/authenticator/LinkMindAuthenticator.kt +++ b/core/network/src/main/java/org/sopt/network/authenticator/LinkMindAuthenticator.kt @@ -10,6 +10,7 @@ import okhttp3.Request import okhttp3.Response import okhttp3.Route import org.sopt.common.intentprovider.IntentProvider +import org.sopt.common.intentprovider.LOGIN import org.sopt.datastore.datastore.SecurityDataStore import org.sopt.network.service.TokenRefreshService import javax.inject.Inject @@ -18,7 +19,7 @@ class LinkMindAuthenticator @Inject constructor( private val dataStore: SecurityDataStore, private val tokenRefreshService: TokenRefreshService, @ApplicationContext private val context: Context, - private val intentProvider: IntentProvider, + @LOGIN private val intentProvider: IntentProvider, ) : Authenticator { override fun authenticate(route: Route?, response: Response): Request? { if (response.code == CODE_TOKEN_EXPIRED) { @@ -37,7 +38,7 @@ class LinkMindAuthenticator @Inject constructor( runBlocking { dataStore.clearAll() } - ProcessPhoenix.triggerRebirth(context, intentProvider.getAuthIntent()) + ProcessPhoenix.triggerRebirth(context, intentProvider.getIntent()) }.getOrThrow() return response.request.newBuilder() @@ -46,6 +47,7 @@ class LinkMindAuthenticator @Inject constructor( } return null } + companion object { const val CODE_TOKEN_EXPIRED = 401 } diff --git a/core/network/src/main/java/org/sopt/network/interceptor/AuthenticationIntercept.kt b/core/network/src/main/java/org/sopt/network/interceptor/AuthenticationIntercept.kt index 8bcdac37..1eb3691b 100644 --- a/core/network/src/main/java/org/sopt/network/interceptor/AuthenticationIntercept.kt +++ b/core/network/src/main/java/org/sopt/network/interceptor/AuthenticationIntercept.kt @@ -9,13 +9,14 @@ import okhttp3.Interceptor import okhttp3.Request import okhttp3.Response import org.sopt.common.intentprovider.IntentProvider +import org.sopt.common.intentprovider.LOGIN import org.sopt.datastore.datastore.SecurityDataStore import javax.inject.Inject class AuthenticationIntercept @Inject constructor( private val dataStore: SecurityDataStore, @ApplicationContext private val context: Context, - private val intentProvider: IntentProvider, + @LOGIN private val intentProvider: IntentProvider, ) : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val originalRequest = chain.request() @@ -23,7 +24,7 @@ class AuthenticationIntercept @Inject constructor( val response = chain.proceed(authRequest) if (response.code == CODE_INVALID_USER) { runBlocking { dataStore.setAutoLogin(false) } - ProcessPhoenix.triggerRebirth(context, intentProvider.getAuthIntent()) + ProcessPhoenix.triggerRebirth(context, intentProvider.getIntent()) } return response } diff --git a/feature/login/src/main/java/org/sopt/login/onboarding/LoginActivity.kt b/feature/login/src/main/java/org/sopt/login/onboarding/LoginActivity.kt index 07700ffe..89cb8981 100644 --- a/feature/login/src/main/java/org/sopt/login/onboarding/LoginActivity.kt +++ b/feature/login/src/main/java/org/sopt/login/onboarding/LoginActivity.kt @@ -12,9 +12,10 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch +import org.sopt.common.intentprovider.IntentProvider +import org.sopt.common.intentprovider.MAIN import org.sopt.datastore.datastore.SecurityDataStore import org.sopt.login.databinding.ActivityLoginBinding -import org.sopt.maincontainer.MainActivity import org.sopt.oauthdomain.interactor.OAuthInteractor import org.sopt.ui.context.toast import org.sopt.ui.view.UiState @@ -31,6 +32,10 @@ class LoginActivity : AppCompatActivity() { @Inject lateinit var dataStore: SecurityDataStore + @MAIN + @Inject + lateinit var intentProvider: IntentProvider + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityLoginBinding.inflate(layoutInflater) @@ -43,8 +48,7 @@ class LoginActivity : AppCompatActivity() { private fun initCheckAutoLogin() { lifecycleScope.launch { if (dataStore.flowAutoLogin().first()) { - val intent = Intent(this@LoginActivity, MainActivity::class.java) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + val intent = intentProvider.getIntent() startActivity(intent) } } @@ -57,14 +61,12 @@ class LoginActivity : AppCompatActivity() { when (state.data.isRegistered) { true -> { dataStore.setAutoLogin(true) - val intent = Intent(this@LoginActivity, MainActivity::class.java) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + val intent = intentProvider.getIntent() startActivity(intent) } false -> { - val intent = Intent(this@LoginActivity, MainActivity::class.java) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + val intent = intentProvider.getIntent() startActivity(intent) } } diff --git a/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsFragment.kt b/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsFragment.kt index 395cc8e1..6a1261f4 100644 --- a/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsFragment.kt +++ b/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsFragment.kt @@ -11,6 +11,7 @@ import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import org.sopt.common.intentprovider.IntentProvider +import org.sopt.common.intentprovider.LOGIN import org.sopt.datastore.datastore.SecurityDataStore import org.sopt.mainfeature.R import org.sopt.mypage.databinding.FragmentSettingsBinding @@ -25,6 +26,7 @@ class SettingsFragment : Fragment() { private val viewModel: SettingsViewModel by viewModels() @Inject + @LOGIN lateinit var intentProvider: IntentProvider @Inject @@ -60,7 +62,7 @@ class SettingsFragment : Fragment() { when (state) { is UiState.Success -> { dataStore.setAutoLogin(false) - val intent = intentProvider.getAuthIntent() + val intent = intentProvider.getIntent() startActivity(intent) requireActivity().finish() } @@ -77,7 +79,7 @@ class SettingsFragment : Fragment() { when (state) { is UiState.Success -> { dataStore.setAutoLogin(false) - val intent = intentProvider.getAuthIntent() + val intent = intentProvider.getIntent() startActivity(intent) requireActivity().finish() }