What it is
Expiration bounds credential lifetime. Refresh exchanges an eligible longer-lived credential for a new access credential. Logout terminates the chosen session lifecycle. Server sessions can be invalidated centrally; self-contained access tokens may remain usable until expiry unless validation also checks revocation state.
Why you need it
Deleting a browser value does not destroy a stolen copy. You need to state exactly how long access may persist and whether logout affects one device or every device.
How it works
- Validate the current session or refresh credential against its lifetime and revocation rules.
- On refresh, issue new credentials through an atomic rotation policy with replay handling.
- On logout, revoke the relevant server session or refresh family and clear the browser cookie.
- Reject future access according to the documented immediate or bounded-revocation guarantee.
Revoking an opaque session
POST /logout: // CSRF-protected
token = readSessionCookie(request)
sessions.delete(hash(token))
clearCookieWithMatchingScope()
return 204
authenticate(token):
session = sessions.find(hash(token))
if missing or expired: reject
return session.userIdA deleted session record makes an old opaque token unusable when every request checks the authoritative state. Cached state needs a compatible freshness rule. JWT access tokens need a separate revocation design if immediate logout is required.
Download the file and run node backend-auth.mjs with Node.js 22 or newer. It tests an in-memory auth model; it is not a production login server.
Good practices and why
- Use server-enforced idle and absolute limits where appropriate, with a deliberate remember-me policy.
- Handle simultaneous refresh attempts without accidental duplicate issuance, and make logout safe to repeat.
Common mistakes
- Issuing a refresh token that never expires or can be reused indefinitely without detection.
- Claiming immediate logout while checking only an access token’s signature and expiry.
Try it yourself
Use the lab to create two sessions. Log out one and verify the other still works. Explain how you would implement logout everywhere.
What a successful result looks like
The logged-out token is rejected, the second session remains active, and your explanation distinguishes device-specific from account-wide revocation.
0 / 6000 characters · Saved on this device. Do not include passwords or private data.
Check your understanding
Answer the understanding check correctly to record exercise completion.
Related interview practice
These scenarios add constraints and follow-up questions to the concepts you just learned.
Further reading
- OWASP: authentication ↗
- OWASP: password storage ↗
- OWASP: session management ↗
- MDN: Set-Cookie ↗
- IETF: JWT best current practices ↗
Selected primary references · reviewed 2026-10-09. Examples are educational; use your framework’s documented integration guidance when building a deployed system.