interplay between auth-refresh & retry-exchange when internet is disconnected and request is made #3534
Unanswered
tom2strobl
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there community!
I have a more general question I'd love to hear your feedback on:
I run an electron app where I'm using urql and it sometimes happens that when a user walks to their office and opens up their laptop my electron app is immediately trying to request new data for the day, even though an internet connection might not be up yet. This would be trivial since the
retryExchangeshould cover that case: network error, retrying until network is up again and everything is fine. The issue is that more often than one would like to think a jwt expires before.The docs lead me to believe that it's a best practice to leverage
willAuthErrorto check if the token is expired andrefreshAuthto then finally refresh the token.The problem is, since the token expiry check in
willAuthErroris network-independent it will see that it's expired and runrefreshAutheven though there is no internet connection, inevitably resulting in a fail. Now what I do in that case for safety reasons is to logout the user to avoid any corrupted state. From there without a connection the user is not able to login and with a connection everything is fine anyway.Unfortunately for some users due to the timing of how slow their internet is connected after opening the laptop that means they have to log in everyday which is horrible UX I'm trying to fix.
Here's my
authExchangeandretryExchange:(note that
isJWTErrorandcheckJWTIsExpiredwork fine and are omitted for brevity and thatensureAuthStateeither directly returns a jwt or fetches a new one using a refresh token)So long story short, is it in my case wise to simply remove
willAuthError? In my head that would mean that even if a jwt is expired (the app wouldn't know that yet) before an internet connection is up it will always just network error which will be retried by the retryExchange until internet is back up and then it woulddidAuthErrorwith the expired jwt and cleanly refresh the token.Or is that a bad idea due to some internals?
Beta Was this translation helpful? Give feedback.
All reactions