I use ktor client with the Bearer Auth plugin. I ...
# ktor
p
I use ktor client with the Bearer Auth plugin. I have one
HttpClient
that I instantiate at startup and hand over to all my remote data source classes via Koin. So basically a singleton. 1. Is that the best practice or should I create a client for every request? Or something else? With that approach I’m running into the problem of not being able to “logout” so to speak. As in: the
bearerAuth.loadTokens
gets called once on creation instead of on every web request. 2. How can I remove the bearer token from the
HttpClient
, so that it knows to
loadTokens
once again? 3. If my approach with just one
HttpClient
at the same time is valid and it’s not possible to remove the tokens, would it be proper to just create a new
HttpClient
on every logout? It would certainly be the easy way out, but is there something better?
r
It’s possible to clear the token, with this ugly piece of code
Copy code
client.plugin(Auth)!!.providers.filterIsInstance<BearerAuthProvider>().first().clearToken()
👍 2
p
That sounds promising, on what interface / class is
.plugin
declared? I can’t find it on my
HttpClient
I’m using version
1.6.7
r
in 1.6.7 you can use
client[Auth]
syntax
p
lovely, thank you so much!
👍 1
107 Views