LEARN. PRACTICE. EXPLAIN.
Learning paths & interview practiceP
← Build a login system
BUILD → VERIFY → EXPLAIN · STEP 3 OF 6

Stay logged in after refreshing

Let the browser send a cookie and let the server decide whether it is valid.

UNDERSTAND

Bring these concepts with you

BUILD

Your implementation

  1. Implement sessionCookie and authenticate. Validate the token against server state and reject expired sessions.
  2. Run node starter.mjs and open http://127.0.0.1:3210. Register with fake credentials, log in, and refresh within 60 seconds. The page calls /me to restore the identity.
  3. Inspect the cookie in browser developer tools. The page should not need localStorage or a JavaScript-readable token.
function sessionCookie(token, clear = false) {
  // Return cookie attributes and the intended lifetime.
}
function authenticate(token) {
  // Look up session, enforce expiry, return server-owned identity.
}
Need a hint?
  • A cookie is transport; it is not the source of truth for identity. GET /me must validate the server session each time.
  • Set HttpOnly, SameSite=Strict, Path=/, and Max-Age. This localhost HTTP lab omits Secure; HTTPS deployment requires it.
  • The provided HTTP scaffold rejects state-changing requests with an unexpected Origin or non-JSON content type. Keep these checks.

Saved on this device · 0 / 6000 · Do not include passwords or private data.

VERIFY

Acceptance checks

From the folder containing your downloaded files, run:

node checks.mjs ./starter.mjs 3

This runs checks up to this step. Earlier steps must work first. Mark each result only after checking your implementation; the website does not run or grade it.

Record your attempt to enable the checklist and reference comparison.

Compare with the reference

Attempt the step first, then compare decisions and behavior. There can be more than one correct implementation.

EXPLAIN

Your interviewer asks

A page refresh resets JavaScript state. Why does this login survive it, and why would a server restart end it?

Say your answer aloud, then record the trade-offs and evidence in your notes above.

LOCAL VOICE REHEARSAL

Rehearse your step walkthrough aloud

Target pacing: 02:00 · Stays in this browser only; never uploaded.

00:00/ 02:00
AlifBay Prep