diff --git a/app/src/main/java/org/sopt/official/di/AuthModule.kt b/app/src/main/java/org/sopt/official/di/AuthModule.kt index eddcb5770..99e30868a 100644 --- a/app/src/main/java/org/sopt/official/di/AuthModule.kt +++ b/app/src/main/java/org/sopt/official/di/AuthModule.kt @@ -38,6 +38,8 @@ import org.sopt.official.data.source.api.auth.RemoteAuthDataSource import org.sopt.official.data.source.impl.DefaultLocalAuthDataSource import org.sopt.official.data.source.impl.DefaultRemoteAuthDataSource import org.sopt.official.domain.repository.AuthRepository +import org.sopt.official.feature.auth.ProvidesIntent +import org.sopt.official.network.authenticator.ProvidesIntents import retrofit2.Retrofit import javax.inject.Singleton @@ -68,5 +70,9 @@ object AuthModule { @Binds @Singleton fun bindLocalAuthDataSource(dataSource: DefaultLocalAuthDataSource): LocalAuthDataSource + + @Binds + @Singleton + fun bindIntent(providesIntents: ProvidesIntent): ProvidesIntents } } diff --git a/app/src/main/java/org/sopt/official/feature/auth/ProvidesIntent.kt b/app/src/main/java/org/sopt/official/feature/auth/ProvidesIntent.kt new file mode 100644 index 000000000..e45da43d2 --- /dev/null +++ b/app/src/main/java/org/sopt/official/feature/auth/ProvidesIntent.kt @@ -0,0 +1,15 @@ +package org.sopt.official.feature.auth + +import android.content.Context +import android.content.Intent +import dagger.hilt.android.qualifiers.ApplicationContext +import org.sopt.official.network.authenticator.ProvidesIntents +import javax.inject.Inject + +class ProvidesIntent @Inject constructor( + @ApplicationContext private val context: Context +) : ProvidesIntents { + override fun getAuthActivityIntent(): Intent = + AuthActivity.newInstance(context) + +} \ No newline at end of file diff --git a/core/network/src/main/java/org/sopt/official/network/authenticator/SoptAuthenticator.kt b/core/network/src/main/java/org/sopt/official/network/authenticator/SoptAuthenticator.kt index 413b25bc8..389382a7b 100644 --- a/core/network/src/main/java/org/sopt/official/network/authenticator/SoptAuthenticator.kt +++ b/core/network/src/main/java/org/sopt/official/network/authenticator/SoptAuthenticator.kt @@ -25,6 +25,8 @@ package org.sopt.official.network.authenticator import android.content.Context +import android.content.Intent +import com.jakewharton.processphoenix.ProcessPhoenix import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.runBlocking import okhttp3.Authenticator @@ -43,7 +45,8 @@ import javax.inject.Singleton class SoptAuthenticator @Inject constructor( private val dataStore: SoptDataStore, @Auth(false) private val service: AuthService, - @ApplicationContext private val context: Context + @ApplicationContext private val context: Context, + private val providesIntent: ProvidesIntents ) : Authenticator { override fun authenticate(route: Route?, response: Response): Request? { if (response.code == 401) { @@ -59,7 +62,7 @@ class SoptAuthenticator @Inject constructor( }.onFailure { dataStore.clear() Timber.e(it) -// ProcessPhoenix.triggerRebirth(context, AuthActivity.newInstance(context)) + ProcessPhoenix.triggerRebirth(context, providesIntent.getAuthActivityIntent()) }.getOrThrow() return response.request.newBuilder() @@ -69,3 +72,7 @@ class SoptAuthenticator @Inject constructor( return null } } + +interface ProvidesIntents { + fun getAuthActivityIntent(): Intent +} \ No newline at end of file diff --git a/core/network/src/main/java/org/sopt/official/network/persistence/SoptDataStore.kt b/core/network/src/main/java/org/sopt/official/network/persistence/SoptDataStore.kt index 93ed4908d..eb474d584 100644 --- a/core/network/src/main/java/org/sopt/official/network/persistence/SoptDataStore.kt +++ b/core/network/src/main/java/org/sopt/official/network/persistence/SoptDataStore.kt @@ -109,7 +109,7 @@ class SoptDataStore @Inject constructor( var userStatus: String set(value) = store.edit { putString(USER_STATUS, value) } - get() = store.getString(USER_STATUS, UserStatus.UNAUTHENTICATED.value) ?: UserStatus.UNAUTHENTICATED.value + get() = store.getString(USER_STATUS, UNAUTHENTICATED) ?: UNAUTHENTICATED var pushToken: String set(value) = store.edit { putString(PUSH_TOKEN, value) } @@ -124,18 +124,7 @@ class SoptDataStore @Inject constructor( private const val KEY_ALIAS_AUTH = "alias.preferences.auth_token" private const val ANDROID_KEY_STORE = "AndroidKeyStore" private const val PUSH_TOKEN = "push_token" + private const val UNAUTHENTICATED="UNAUTHENTICATED" - enum class UserStatus( - val value: String - ) { - ACTIVE("ACTIVE"), - INACTIVE("INACTIVE"), - UNAUTHENTICATED("UNAUTHENTICATED"); - - companion object { - fun of(value: String) = entries.find { it.value == value } - ?: throw IllegalArgumentException("Invalid user status: $value") - } - } } }