Alvin Dizon
03/28/2024, 2:32 AMAuthorizationInterceptor
which is a Retrofit Interceptor that just adds a Bearer
header to the request. Currently, this header is stored to shared preferences, so it was being used in a synchronous manner. If I store the header in DataStore
, with `DataStore`'s async API, is runBlocking
the way to go to access the said header within the Interceptor's intercept()
function? So something like this:
override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest = chain.request()
val authToken = runBlocking {
dataStore.header.firstOrNull()
}
val withHeader =
originalRequest.newBuilder().header("Authorization", "Bearer $authToken").build()
return chain.proceed(withHeader)
}
SanjayKarki
03/28/2024, 8:01 AM