Профиль, редактирование без аватара
This commit is contained in:
@@ -5,10 +5,15 @@ import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
|
||||
@Singleton
|
||||
class AuthInterceptor @Inject constructor(
|
||||
private val tokenManager: TokenManager
|
||||
private val tokenManager: TokenManager,
|
||||
private val navigationManager: core.utils.NavigationManager,
|
||||
private val authRepositoryProvider: javax.inject.Provider<auth.domain.repository.AuthRepository>
|
||||
) : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val token = tokenManager.getToken()
|
||||
@@ -17,6 +22,17 @@ class AuthInterceptor @Inject constructor(
|
||||
addHeader("Authorization", "Bearer $it")
|
||||
}
|
||||
}.build()
|
||||
return chain.proceed(request)
|
||||
|
||||
val response = chain.proceed(request)
|
||||
|
||||
if (response.code == 401) {
|
||||
// Global logout
|
||||
kotlinx.coroutines.GlobalScope.launch(kotlinx.coroutines.Dispatchers.Main) {
|
||||
authRepositoryProvider.get().logout()
|
||||
navigationManager.logout()
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user