Exercise 09 worked solution
Compare after completing your own attempt. Only session-policy.mjs differs from the student application; the helper, server, page and checks are shared.
Repair
import { revokeSession } from './session-helpers.mjs';
export function endSession(state, token) {
return revokeSession(state, token);
}
Removing the current token from the server's session store means the normal protected endpoint rejects every later copy of that token. The browser also clears its own current token. Other session tokens remain valid; a new login can create a fresh session.
Run and verify
From the repository root:
cd exercises/09-authentication-failures/solution
node checks.mjs
node server.mjs
Expect all 10 checks to pass, ending with 10 passed; 0 failed and exit code 0. Stop other lesson servers first and open http://127.0.0.1:3000. Log in as alice@campus.example / Campus-demo-42!, request the profile, capture the token, log out, and replay it: HTTP 401. Log in again and request the profile: HTTP 200. Two independently signed-in tabs remain independent when one logs out.
Do not restart between capture and replay. The restart required to load the code repair also clears the store, so capture a new token after it. These controls demonstrate one logout policy; they do not form a production authentication framework. Keep all use on loopback with fictional credentials.