I have an application that makes multiple requests to an API to render parts of the page.
When the user's access token expires the first request sends the refresh token, gets the new access token and updates the cookie storing it, but as the requests are async, sometimes before updating the cookie the other requests send the old, now invalid token, so the API returns 401 Unauthorized
.
How should I handle this? Is there a way to make the other requests wait for the access token to refresh?