Skip to main content

Authentication

My mental model: Authentication = who are you. Authorization = what can you do.


Auth Flow Comparison​

JWT-based (stateless)​


Session vs JWT​

SessionJWT
StateStored server-sideStateless
RevocationInstant (delete session)Wait for expiry (or maintain revocation list)
ScalabilityNeeds shared session store (Redis)Easy to scale horizontally
Mobile-friendlyHarder (cookie handling)Better
My preferenceMonolith + SSR appsAPIs, microservices, mobile

OAuth2 / OIDC Flow (for social login / SSO)​

OIDC adds the id_token (user identity) on top of OAuth2 (API access). Use OIDC when you need to know who the user is, not just access their resources.


My Default Stack​

Use caseMy choice
New Next.js appNextAuth.js / Auth.js
Supabase projectSupabase Auth (built-in)
Backend API onlyJWT (RS256) with short expiry
Enterprise SSOSAML or OIDC via provider

Reference​