System Design · Middle · Question 48 of 75
How do you handle an access token expiring while the user is working?
- ✓Correct answer: Intercept 401, refresh the token once and retry pending requests
- 2Log the user out immediately and lose unsaved data
- 3Refresh the token before every request, even if it's still valid
Explanation
Several parallel requests may get 401 at the same time - the refresh must run once (a shared promise), while the other requests wait for it and are retried. If the refresh fails, log out while preserving drafts.