

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Authentication
incomplete
2: Stateless vs. Stateful Authentication
incomplete
3: What Are Sessions?
incomplete
4: What Are Cookies?
incomplete
5: Cookie Security
incomplete
6: Session Lifetime
incomplete
7: Password Resets
incomplete
8: Broken Password Reset Flow
incomplete
9: OAuth 2.0
incomplete
10: SAML and OIDC
incomplete
11: API Keys
incomplete
12: Reauthentication
incomplete
13: Authentication Misconceptions
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
An authenticated session is created when a user successfully logs in. It's a record stored on the server that says "When a user presents this session ID, let them access this account while the session is valid."
In a typical browser flow, the client stores and sends that ID in a cookie, and the server re-checks it against the session in the database on every request.
A session ID is a reference to server-side data (often a row in a sessions table) that stores:
id, which is secret and given to the client)user_id)expires_at)revoked_at, can be NULL if the session is still valid)For each request, the server reads the session ID from the Cookie header, looks up the record, and rejects sessions that are missing, expired, or revoked.
A session ID is a bearer credential, so it needs to stay secret. Don't put raw session IDs in URLs or logs.
Bearly Secure uses sessions to protect the user account page. To confirm that things are working correctly, let's have the app log a message whenever an authenticated user reaches that page.
Add an account_accessed log event to the GET /account route.
Ensure invalid sessions still redirect to /login without writing the account_accessed event.
[email protected]password123{
"timestamp": "2026-08-13T19:31:24.639Z",
"event": "account_accessed",
"userId": 1,
"email": "[email protected]",
"expiresAt": "2026-09-12T19:31:20.138Z"
}
With Bearly Secure still running, run and submit the CLI tests from the project root.