step 10.4: done

This commit is contained in:
bepis
2026-10-22 22:55:24 +11:00
parent 441efb06bd
commit 81ad47c138
5 changed files with 187 additions and 16 deletions
+5 -4
View File
@@ -7,10 +7,10 @@
> - Keep Session Log entries to one or two lines.
## Current Focus
- **Phase:** 10.3
- **Step:** 10.4 — Fix GET /api/auth/me and POST /api/auth/login to return real username and hasHero
- **Phase:** 10.4
- **Step:** 10.5 — Add a landing page `public/index.html` (title, one-line tagline, Login/Register buttons; "Play" button if already logged in with a hero). Fix the "Return to Emberfall" links on the 404/500 pages. Add a link-checker test.
- **Blocked?** No
- **Last verified working command:** `npm test` — 184/184 passing (85 unit + 99 integration incl. 2 new 10.3 tests), 2026-10-22 step 10.3
- **Last verified working command:** `npm test` — 187/187 passing (85 unit + 99 integration incl. 3 new 10.4 tests), 2026-10-22 step 10.4
## Project Health
| Item | State |
@@ -148,8 +148,9 @@
*Acceptance:* test with a fixed rng asserts the exact gold reward; a test using `time.setNow` proves claim is rejected before `ends_at` and accepted after.
*Verified:* 2 new integration tests (fixed rng → exact gold=10, time.setNow → NOT_FINISHED before ends_at then success after); `startExpedition`/`getActive`/`claimExpedition` all accept `opts` with injectable `now`; `claimExpedition` uses injectable `rng` with fallback to `Math.random`; import changed from destructured `{now}` to `const time = require(...)`.
### B. Accounts & navigation
- [ ] **10.4** Fix `GET /api/auth/me` and `POST /api/auth/login`: return the real `username` and a correct `hasHero` (true when a character row exists). Store the username in the session at login/register. Update `public/js/login.js` and `public/js/create-hero.js`: returning players with a hero go to `/game.html`; players without go to `/create-hero.html`; `/create-hero.html` redirects to `/game.html` if a hero already exists.
- [x] **10.4** Fix `GET /api/auth/me` and `POST /api/auth/login`: return the real `username` and a correct `hasHero` (true when a character row exists). Store the username in the session at login/register. Update `public/js/login.js` and `public/js/create-hero.js`: returning players with a hero go to `/game.html`; players without go to `/create-hero.html`; `/create-hero.html` redirects to `/game.html` if a hero already exists.
*Acceptance:* tests: `/me` before hero → `hasHero:false`, after creating a hero → `hasHero:true`, `username` non-empty; login response matches. No frontend code assumes `hasHero` is always false.
*Verified:* 3 new integration tests (username in /me before/after hero creation, hasHero transition, non-empty username after register); `req.session.username` set in both `handleRegister` and `handleLogin`; `create-hero.js` checks `/me` on DOMContentLoaded and redirects to `/game.html` if `hasHero` is true; 187/187 tests pass.
- [ ] **10.5** Add a landing page `public/index.html` (title, one-line tagline, Login/Register buttons; "Play" button if already logged in with a hero). Fix the "Return to Emberfall" links on the 404/500 pages so they work. Add a link-checker test that reads every `public/*.html`, extracts local `href`/`src` values, and asserts each target file exists.
*Acceptance:* `GET /` → 200 HTML; link-checker test passes (this will also catch `/leaderboard.html` until 10.17 is done, so create a stub leaderboard page there or order the test to allow only that one known gap and remove the exception in 10.17).
### C. Security & robustness