JWT vs Session Authentication in MERN Apps

Stateless tokens or server sessions? The trade-offs that matter, and the hybrid setup I use for most client projects.
Almost every MERN project starts with the same question: JWTs or sessions? Both work. The right choice depends on how you handle logout, scaling and where the token is stored.
Server sessions
The server stores session data and the browser holds a random session id in a cookie. Logging out or revoking access is instant: delete the session. The cost is a shared store, such as Redis, once you run more than one server.
JWTs
A JWT carries signed claims, so any server can verify it without a database lookup. The catch is revocation: a stolen token stays valid until it expires.
The hybrid I use
- A short-lived access token, around 15 minutes, used for API calls.
- A long-lived refresh token stored in an httpOnly, Secure, SameSite cookie.
- Refresh tokens stored server-side so they can be rotated and revoked.
This keeps API calls stateless and fast while still allowing real logout and "sign out of all devices".
Where to store tokens
Avoid localStorage for anything long-lived: any XSS bug can read it. httpOnly cookies cannot be read by JavaScript, which removes a whole class of token theft.
res.cookie("refresh", token, {
httpOnly: true,
secure: true,
sameSite: "strict",
path: "/api/auth/refresh",
maxAge: 30 * 24 * 60 * 60 * 1000,
});Rule of thumb
If you need instant revocation and run a single app, sessions are simpler. If you have several services or mobile clients, use the hybrid token approach.









