I have a login endpoint by which I receive an authToken and a refreshToken. The first one expires in an hour, so I should use the second one to refresh it and continue the application flow.
Now my app is filled with retrofit calls all over the place and I potentially could get a 401
at any given moment, so how can I make it so every time I get a 401
a refresh token is issued, and then the original request retried?
This is my refresh signature:
@POST("/auth/actions/refresh")
fun refreshToken(@Body tokenRefresh: TokenRefresh): Single<LoginResponse>
I thought about making a base repository class with a method withAuth()
that takes any Observable
/Single
/Flowable
and then applies this logic but I cannot find a way to implement it.
Saw a bunch of implementations but none of them match my needs... can anyone push me in the right direction?
This is the closest I've found, however there seems to be some errors on the flatmapping