Migrate frontend to Nuxt UI, harden backend, add tests #3

Merged
LiamPietralla merged 3 commits from claude/repo-improvements-nuxtui-542ed8 into main 2026-11-16 12:43:20 +11:00
Owner

Summary

Three commits, one per area:

1. Backend hardening

  • Rate limit login (5 attempts/min per IP) with a JSON 429 response
  • Constant-time password comparison; login refused if no password is configured
  • Explicit SameSite=Strict auth cookie; failed logins logged with client IP
  • Stop logging door codes (update log lines and the SMS body)
  • Global exception handler (JSON 500) instead of per-action try/catch -> 400; 404 for a missing person, 502 for failed lock writes
  • Codes must be ASCII digits only (int.TryParse accepted +123, -123, whitespace)
  • Person name and E.164 phone number validation; sending an unset code is rejected
  • TwiloOptions -> TwilioOptions, typo fixes

2. Frontend: Nuxt 4 + Nuxt UI

  • Upgrade to Nuxt 4 (sources under app/), add @nuxt/ui, Tailwind v4 and Lucide icons; drop @nuxtjs/tailwindcss
  • Replace the custom Yale* components, Modal, Navbar and icon components with Nuxt UI equivalents (UTable, UModal, UCard, UHeader, UBadge, toasts, ...)
  • Dark/light toggle and a logout button
  • New useApi composable: central base URL/credentials, JSON-encoded bodies, error handling, redirect to login when the session expires
  • Fixes: modal listener leak, missing People heading, unhandled fetch errors, hand-built JSON bodies (passwords with " broke login), logged-in users hitting /login
  • Tables now fit on phone screens (the Delete button was clipped)
  • README screenshots retaken

3. Tests + CI

  • Backend: 42 xUnit integration tests (packages/backend.Tests) using WebApplicationFactory with a fake lock
  • Frontend: 37 Vitest tests for useApi, the auth middleware, LoginForm, UserCodeList, PeopleList
  • CI runs both suites before building

Notes for review

  • Behaviour changes: phone numbers must now be international format (+61400000000); the auth cookie is SameSite=Strict (assumes the frontend and API share a site, which was already needed for the previous default Lax cookie); failed lock writes return 502 and unexpected errors 500 rather than 400.
  • Not exercised: a real Z-Wave lock, real Twilio SMS, the Docker builds, and the updated CI workflow (only the equivalent commands were run locally).
  • Out of scope: dotnet build reports known advisories on OpenTelemetry 1.15.0, SQLitePCLRaw.lib.e_sqlite3 2.1.11 and Microsoft.OpenApi 2.4.1; worth a separate dependency update.
  • backend.Tests isn't added to YaleAccess.sln (CI/dotnet test don't need it).

Test plan

  • dotnet test packages/backend.Tests (42 passing)
  • pnpm test and pnpm typecheck in packages/frontend (37 passing, clean)
  • pnpm build in packages/frontend
  • Manual run in mock mode (login, wrong password, code list, edit validation, People page, mobile layout)
  • CI green on this branch
  • Docker images build
## Summary Three commits, one per area: ### 1. Backend hardening - Rate limit login (5 attempts/min per IP) with a JSON 429 response - Constant-time password comparison; login refused if no password is configured - Explicit `SameSite=Strict` auth cookie; failed logins logged with client IP - Stop logging door codes (update log lines and the SMS body) - Global exception handler (JSON 500) instead of per-action `try/catch -> 400`; 404 for a missing person, 502 for failed lock writes - Codes must be ASCII digits only (`int.TryParse` accepted `+123`, `-123`, whitespace) - Person name and E.164 phone number validation; sending an unset code is rejected - `TwiloOptions` -> `TwilioOptions`, typo fixes ### 2. Frontend: Nuxt 4 + Nuxt UI - Upgrade to Nuxt 4 (sources under `app/`), add `@nuxt/ui`, Tailwind v4 and Lucide icons; drop `@nuxtjs/tailwindcss` - Replace the custom `Yale*` components, `Modal`, `Navbar` and icon components with Nuxt UI equivalents (`UTable`, `UModal`, `UCard`, `UHeader`, `UBadge`, toasts, ...) - Dark/light toggle and a logout button - New `useApi` composable: central base URL/credentials, JSON-encoded bodies, error handling, redirect to login when the session expires - Fixes: modal listener leak, missing People heading, unhandled fetch errors, hand-built JSON bodies (passwords with `"` broke login), logged-in users hitting `/login` - Tables now fit on phone screens (the Delete button was clipped) - README screenshots retaken ### 3. Tests + CI - Backend: 42 xUnit integration tests (`packages/backend.Tests`) using `WebApplicationFactory` with a fake lock - Frontend: 37 Vitest tests for `useApi`, the auth middleware, `LoginForm`, `UserCodeList`, `PeopleList` - CI runs both suites before building ## Notes for review - **Behaviour changes:** phone numbers must now be international format (`+61400000000`); the auth cookie is `SameSite=Strict` (assumes the frontend and API share a site, which was already needed for the previous default `Lax` cookie); failed lock writes return 502 and unexpected errors 500 rather than 400. - **Not exercised:** a real Z-Wave lock, real Twilio SMS, the Docker builds, and the updated CI workflow (only the equivalent commands were run locally). - **Out of scope:** `dotnet build` reports known advisories on `OpenTelemetry` 1.15.0, `SQLitePCLRaw.lib.e_sqlite3` 2.1.11 and `Microsoft.OpenApi` 2.4.1; worth a separate dependency update. - `backend.Tests` isn't added to `YaleAccess.sln` (CI/`dotnet test` don't need it). ## Test plan - [x] `dotnet test packages/backend.Tests` (42 passing) - [x] `pnpm test` and `pnpm typecheck` in `packages/frontend` (37 passing, clean) - [x] `pnpm build` in `packages/frontend` - [x] Manual run in mock mode (login, wrong password, code list, edit validation, People page, mobile layout) - [ ] CI green on this branch - [ ] Docker images build
LiamPietralla added 3 commits 2026-11-16 12:23:46 +11:00
- Rate limit login (5 attempts/min per IP) with a JSON 429 response
- Constant-time password comparison; refuse login if no password is configured
- Explicit SameSite=Strict auth cookie; log failed logins with client IP
- Stop logging door codes (update log lines and the SMS body)
- Replace per-action try/catch -> 400 with a global exception handler (JSON 500)
- Return proper statuses: 404 for missing person, 502 for failed lock writes
- Validate codes as ASCII digits only (int.TryParse accepted +/-/whitespace)
- Validate person name and E.164 phone number; reject sending an unset code
- Rename TwiloOptions -> TwilioOptions and fix message typos
- Expose Program for integration tests
- Upgrade to Nuxt 4 (sources under app/), add @nuxt/ui, Tailwind v4 and
  Lucide icons; drop @nuxtjs/tailwindcss
- Replace the custom Yale* components, Modal, Navbar and icon components with
  UButton/UInput/UModal/UTable/UCard/UHeader/UBadge/UAlert and toasts
- Add dark/light mode toggle and a logout button
- Add a useApi composable: central base URL/credentials, JSON-encoded bodies,
  error handling, and redirect to login when the session expires
- Fix modal listener leak, missing People heading, unhandled fetch errors and
  login redirect for already-authenticated users
- Make the code and people tables fit on phone screens
- Retake README screenshots
Add backend and frontend tests and run them in CI
Build and Publish / Build Yale Access Frontend (pull_request) Successful in 1m17s
Build and Publish / Push Yale Access Frontend Docker Image (pull_request) Skipped
Build and Publish / Build Yale Access Backend (pull_request) Successful in 2m12s
Build and Publish / Push Yale Access Backend Docker Image (pull_request) Skipped
4fe6f9d7b5
- Backend: xUnit integration tests (auth, rate limiting, people, lock codes,
  validation, error handling) using WebApplicationFactory with a fake lock
- Frontend: Vitest + Nuxt test utils for useApi, the auth middleware,
  LoginForm, UserCodeList and PeopleList
- Run both suites in CI before building
LiamPietralla merged commit ea7fc867dd into main 2026-11-16 12:43:20 +11:00
LiamPietralla deleted branch claude/repo-improvements-nuxtui-542ed8 2026-11-16 12:43:20 +11:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LiamPietralla/yale-user-access#3