All jobs / Frontend / web developer / Security
Frontend / web developer interview question · 3–5 years
Two 401s trigger two refresh calls and one of them logs the user out. How do you design the client?
The strongest answer
Single-flight the refresh, queue the original requests, retry them, and log out only when refresh fails
Why it works
Refresh is a critical section. One in-flight refresh, everyone else waits.
What a good answer covers
- One refresh at a time.
- Queue callers.
- Retry originals after success.
- Logout only on refresh failure; keep refresh out of JS if you can.
Answers that fall short
- Close, but not the strongest: Refresh independently on every 401
Parallel refresh is how you rotate into an invalid token. - Weak: Log out on the first 401
First 401 may be a single expired access token. - Red flag: Store the refresh token in localStorage and send it to third-party scripts
Refresh tokens in JS and in third parties are a session gift.
Who gets asked this
More Security questions
- Product wants full click tapes plus form field values in the frontend logger. How do you respond?
- Legal says marketing pixels cannot run before consent. How do you architect the frontend?
- A junior's PR works but has an XSS hole and no tests. How do you mentor in review?
- How do you keep consent state consistent across web, a WebView, and a pixel manager?
- Marketing wants to render a CMS HTML snippet in React. Strongest answer?
- A cookie-session SPA posts state-changing requests. What do you do in the browser about CSRF?
- Auth token in localStorage versus an httpOnly cookie for a SPA — how do you argue it?
- You need a small inline boot script but CSP forbids unsafe-inline. What do you do?