I have a `AuthorizationInterceptor` which is a Ret...
# android
a
I have a
AuthorizationInterceptor
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:
Copy code
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)
    }
s
Yes you can use runblocking
👍 1