Session vs JWT
A session keeps your login on the server, while a JSON Web Token carries it inside the token. With a session, the browser holds only an ID. The server looks it up on each request. A JWT holds the facts and a signature, so the server can check it with no lookup. A session can be ended at once; a JWT stays good until it runs out.
Session (Web)
How a site remembers you are logged in as you move from page to page.
A session is how a website remembers you are logged in from one page to the next. After you log in, the server makes a random session ID and keeps your details beside it. Your browser stores that ID in a cookie and sends it with every request. The server looks it up and knows it is you. Logging out deletes the session on the server.
JSON Web Token (JWT)
A signed token in three parts. It carries facts about a user.
A JSON Web Token is a small, signed token that carries facts about a user. It has three parts joined by dots: a header, a payload of facts and a signature. The payload might say the user's ID and when the token runs out. The server checks the signature, so it can trust the facts without looking them up. The payload is only encoded, not hidden, so it must never hold secrets.
In one line
- Session (Web)
- How a site remembers you are logged in as you move from page to page.
- JSON Web Token (JWT)
- A signed token in three parts. It carries facts about a user.