authExchange: proactively update authState #1642
Replies: 2 comments 1 reply
-
A solution that I've used is to use
This will put you into |
Beta Was this translation helpful? Give feedback.
-
You'll have to write your own auth state management and use it in parallel. This isn't uncommon; you'd probably want some kind of auth singleton that manages your token and return it in the I'd actually say though that if you're worried that your access tokens are too short lived, the solution isn't to send requests more often. The solution is to make them live longer. |
Beta Was this translation helpful? Give feedback.
-
I'm using authExchange with a pretty standard JWT-based auth flow. Since the access tokens are short lived, I expect that
willAuthError
/didAuthError
will trigger frequently, causing re-auth. Since our JWTs include an expiration time, I could use that to proactively update theauthState
even before the JWT actually expires.I see several options how to ingrate that feature:
addAuthToOperation
: if I detect that the JWT is about to expire, somehow tell authExchange to trigger an asyncgetAuth
flow.willAuthError
: indicate to the authExchange to run the operation as usual, but also thegetAuth
flow in parallel to that.shouldAuth
). The authExchange would call this function during each request, and if it returns true then trigger an asyncgetAuth
.Beta Was this translation helpful? Give feedback.
All reactions