Repository navigation
Refreshing token and more than 2 async requests. #6249
Unanswered
vladdominator
asked this question in
Q&A
Replies: 2 comments
|
have the same problem |
0 replies
|
The usual fix is a "single-flight" refresh: keep one in-flight promise and let every 401 await it instead of starting its own refresh. No mutex library needed: let refreshing: Promise<void> | null = null
axios.interceptors.response.use(undefined, async (error) => {
if (error.response?.status !== 401 || error.config._retried) throw error
refreshing ??= refreshToken().finally(() => { refreshing = null })
await refreshing
error.config._retried = true
return axios(error.config)
})
Disclosure: I maintain tanstack-fetch (not official TanStack), which ships this as a built-in single-flight interceptor, with an optional proactive refresh before expiry, if you'd rather not maintain it yourself: https://mohamadgarmabi.github.io/tanstack-fetch/recipes/refresh-token |
0 replies
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.
To update the refresh token for 401 status and for more than 2 requests. I couldn't connect with async-mutex or async-lock via interceptors axios. Could you give ideas on how to implement it?
All reactions