Case Study · Auth · 2022 — 2023
Secure auth flow with short-lived access tokens, refresh rotation, and middleware-guarded routes.
The product needed authentication that was secure by default — resistant to token theft and replay — without forcing users to log in constantly. Long-lived tokens are convenient but dangerous; a single leaked token grants indefinite access. The challenge was balancing security with a smooth session experience.
A multi-tenant SaaS with both browser and API clients. Tokens had to be verifiable statelessly at the edge for performance, yet revocable when a session was compromised — two goals that pull in opposite directions.
Request path
Login
credentials
Auth service
verify
JWT
access + refresh
Middleware
validate
Protected route
granted
Failure recovery & consistency
Access expired
401
Refresh
rotate token
Reuse detected
revoke all
Re-login
forced
Frontend
Backend
APIs
Chose
·Stateless JWT verification at the edge
·Rotation + denylist for revocability
·httpOnly cookies for token storage
Gave up
·Fully stateless logout (needs the Redis denylist)
·Simpler client code (silent refresh adds logic)
·Long sessions without re-auth on sensitive actions
minutes
max exposure window for a leaked access token
100%
compromised sessions revocable in real time
0
tokens reachable by injected client-side scripts