JWT or sessions: choosing authentication for your app

Published 2026-11-06

Two ways to remember a user

After login, the server must recognise the user on later requests. Sessions store state on the server and give the browser an opaque identifier in a cookie. Tokens such as JWTs carry signed claims, so the server can verify them without a lookup. Both work, and each has costs that are easy to underestimate.

Sessions: simple and revocable

With sessions, logging a user out or banning an account takes effect immediately, because the server simply forgets the session. Cookies set as HttpOnly and SameSite are hard for scripts to steal. The cost is shared state: with several servers you need a common session store, and you need CSRF protection for cookie-based requests.

For a web application served from one domain, sessions are usually the simplest safe choice.

Tokens: portable and harder to revoke

A signed token works well for mobile apps, for service-to-service calls and across domains, because no shared session store is required. The price is revocation: a token is valid until it expires, so short lifetimes plus refresh tokens are standard, and immediate logout needs a deny list, which brings back server-side state.

Where the token is stored in a browser matters. Local storage is readable by any script on the page, so a cross-site scripting bug exposes it; a cookie with the right flags is safer.

A decision rule

  • Browser app on a single domain: sessions.
  • Native mobile app or third-party API clients: tokens with short lifetimes and refresh.
  • Several services that must trust the same login: tokens issued by one identity service.
  • Anything needing instant account lockout: sessions, or tokens plus a deny list.

Whichever you pick

Hash passwords with a modern algorithm, rate-limit login attempts, offer two-factor authentication where the data deserves it and keep authorisation checks on the server for every request. Authentication proves who someone is; it does not decide what they may do.

A common mistake: tokens by default

Tokens are fashionable, so many applications adopt them without needing what they offer. The usual result is a single-domain web app that now has to build its own revocation list, refresh flow and storage rules, all to reproduce what a session cookie provided for free. If the only client is your own browser front end on your own domain, start with sessions and add tokens when a real second client appears.

Storing tokens safely in a browser

If you do use tokens in a browser, where they live matters. Anything readable by JavaScript can be stolen by a cross-site scripting bug, so keep lifetimes short, avoid putting sensitive data in the token body, and prefer a secure, HTTP-only cookie where the architecture allows. Pair a short-lived access token with a longer-lived refresh token that can be revoked, and rotate it on use.

Questions to ask before choosing

  • Who are the clients: only a browser, or also mobile apps and other services?
  • Do users and administrators need to be logged out instantly?
  • Will several domains or services need to trust the same login?
  • How will you revoke access when a device is lost?
  • Who maintains the extra moving parts, and are they tested?

© 2026 The Good Fellas