Authentication vs authorization
Understand the idea
Signing in answers who you are. It does not answer what you may touch.
The idea
is the check that this caller is Ada. is the check that Ada may open this note. The first can succeed while the second fails. Bea with a valid session is a known person who is still not the owner. A handler that stops after the session exists has only done the first half.
What changes
| Question | Check | Failure |
|---|---|---|
| Who is this? | Session or token matches a known caller | 401 |
| May this caller do this? | Role, scope, or ownership | 403 |
| Both skipped | The route trusts the path | Anyone who can reach it |
The command
Same building, different doors
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
Ada opening Ada's note is authenticated and authorized. Bea opening Ada's note is authenticated and not authorized. A missing user is neither.
Guided challenge
Separate the two checks
The starter treats every authenticated user as authorized. Change the authorized line so it is true only when the user is the owner.
Separate the two checks
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
{"authenticated":true,"authorized":true}
{"authenticated":true,"authorized":false}
{"authenticated":false,"authorized":false}Hints 0/2
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.