Lesson 9 of 30
Two different answers to 'how does the server remember you're logged in on the next request' — one keeps state on the server, one packs it into the token itself. Neither is simply 'the modern one.'
14 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 2
Is the payload of a JWT encrypted, meaning it's hidden from anyone who intercepts it?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
HTTP itself is stateless — every request is independent, with no memory of the last one. Both approaches exist to answer the same question ("is this request from a logged-in user, and who?") with opposite tradeoffs.
Session-based auth: on login, the server creates a session record (in memory or a database) and gives the browser a session id in a cookie. Every later request sends that cookie; the server looks up the id to find who's logged in. The server holds the actual state.
JWT-based auth (token-based): on login, the server creates a signed token containing the user's info directly ({ userId, role, exp }), and hands it to the client. Every later request sends that token; the server just verifies the signature — no lookup, no stored session, because the token is the proof.
Session: the server stores { sessionId: userId }; the client just holds an opaque cookie pointing to it.
localStorage is readable by any JavaScript on the page, making it vulnerable to XSS; an httpOnly cookie is invisible to JavaScript entirely, closing that specific attack surface (at the cost of needing CSRF protection instead)."Would you use JWTs or sessions for this app, and why?" is a genuine engineering tradeoff question, not a trick with one right answer — a strong response names the real tradeoff (revocability and server state vs. statelessness and scale) instead of treating JWT as an automatic upgrade.