Track 07 · Lesson 16 of 18Identity and login
- 01Authentication vs authorization
- 02Browser storage compared
- 03Sessions versus tokens
- 04Inside a JWT
- 05Access and refresh tokens
- 06Where to keep tokens
- 07Choosing a design
- 08The login lifecycle
- 09The token clock
- 10Dead or just unlucky? Refresh decisions
- 11Inside a secure session cookie
- 12Five tabs, one refresh
- 13“Log in with Google”: OAuth and PKCE
- 14Two-factor login
- 15Storing passwords
- 16Logging out properly
- 17Trade-offs and common mistakes
- 18Compare the designs
Logging out properly
Lesson 16 of 18· 6 min
Logging out should remove every credential and user-specific trace from the device, not just the main session. The next person on that computer may be someone else.
What does logout leave behind?
Pick an implementation, then let someone else sit down
Ana clicks Log out. The app…
- Auth serverRefresh token RT #3 (active)
- Cookieapp_session (sealed refresh token)
- MemoryAccess token JWT C
- MemoryData cache: Ana’s projects
- WebSocketLive channel: Ana’s notifications
- sessionStorageoauth_state, pkce_verifier
- localStoragehas_session = 1
- localStoragedraft:4821 = “Re: salary review…”
- Analyticsidentify(user 4821)
- localStorage · device preferencetheme = dark
Revoke on the server first#
Logout must revoke the refresh token or delete the session on the server, and the revoke call must name the token to revoke: an empty body revokes nothing, a bug that’s easy to ship and hard to notice. Send it with keepalive: true so it finishes even though the page is navigating away. From the user’s point of view, logout always succeeds and always clears the cookie, even if the auth server is unreachable.
Then clear the device#
Broadcast “logout” so other tabs follow. Clear the in-memory token, the session hint, the data cache, sessionStorage (OAuth state, PKCE verifiers), every user-scoped localStorage key (drafts, recent searches), open WebSockets, and the analytics identity. Keep device-scoped preferences like the theme.
Finish with a full reload#
window.location.assign("/login") drops everything in memory in one move: stores, caches, sockets, singletons. It’s the simplest way to guarantee nothing of the previous user survives.
Check yourself