Track 07 · Lesson 16 of 18Identity and login

Track 07 · Identity and login

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
Pick how the app logs out, then let someone else use the computer.

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

Why do a full page reload on logout?