Sessions vs tokens
Understand the idea
A session lives in the server's memory. A token lives in the request.
The idea
A is the coat check. The cookie holds an id such as sid-ada. The server holds the row that says that id is Ada. Logout deletes the row, so the next request with the same cookie finds nothing. A signed token is the letter. The server can verify it without a row, which is why the run still prints token ada after the map is empty. That is useful across many servers, and it is also why logout is not free: you either wait for expiry or you store the ids you have revoked, which starts to look like a session again.
What changes
| Model | Where the state lives | What logout can do immediately |
|---|---|---|
| Server session | A row keyed by the cookie id | Delete the row. The next request fails the lookup. |
| Self-contained token | Inside the token the client sends | Nothing, unless you also store a revocation list or keep the lifetime very short. |
The command
Delete the session, the token still reads
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
The mistake
Check the result
The session line becomes missing after delete. The token line stays ada, and server rows is 0. The signature was enough.
Guided challenge
Delete the session on logout
logout returns the id and leaves the map entry in place. Delete that id so the next line prints missing.
Delete the session on logout
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
EXPECTED RESULT
missing checked
Hints 0/2
Use all hints or make 3 failed checks (0/3).
Free exploration
Change this example and run it again. Each run is a new process. Nothing is saved.
Your variation
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 100 XP. You can always revisit it.