Skip to content

ADR 0003: M2 reviewer sessions and read-only inbox

M1 authenticated capture clients with bearer API keys and exposed read endpoints to those keys as a temporary bridge. The office needs a browser inbox with reviewer identity, a secure session, and no API key in the browser. Review actions are a later M2 slice, so this decision covers login, sessions, and read-only inbox access.

Section titled “Magic links are single-use, hashed, and short-lived”

POST /v1/auth/magic-link creates a 32-byte token, stores only its SHA-256 hash, and expires it after 15 minutes. Verification atomically marks the token used. The email lookup assumes one active account per email for this single-tenant-local slice; hosted multi-tenant login will need a tenant hint.

The local EmailSender adapter logs the link. Outside production, the API also returns the link as devLink so local testing does not require an email provider. Production requires a real sender.

Section titled “Sessions are server-side and cookie-backed”

A session is a 32-byte token whose hash is stored in sessions, with a seven-day expiry and a revocation timestamp. The browser receives the raw token in cd_session:

  • HttpOnly
  • SameSite=Lax
  • Path=/
  • Max-Age=604800
  • Secure when ENVIRONMENT=production

Logout revokes the row and clears the cookie. Cookie-authenticated state changes also require the request Origin to match WEB_BASE_URL.

Read endpoints accept a session or an API key

Section titled “Read endpoints accept a session or an API key”

Towns, parcels, capture list, and capture detail use a combined read middleware. A valid session wins; otherwise an API key is accepted for capture clients and tests. Both resolve to the same tenant id, so the core use cases and repositories remain unchanged.

Uploads and capture submission remain API-key only. /v1/me and logout are session-only.

The SPA uses hash routes (#/login, #/, #/captures/:id) and TanStack Query. The login screen requests a magic link, the list supports status/town/type filters, and detail shows payload, attachments, and audit events. No accept/return/reject/request-information controls exist in this slice.

Hash routing avoids server rewrite configuration until deployment work.

  • Session and magic-link tables require an M2 migration; capture and attachment tables are unchanged.
  • Hosted multi-tenant login needs a tenant hint or organization-specific login URL before real use.
  • Review actions will reuse requireSession and add CSRF tokens before state-changing review routes.
  • Expired session rows accumulate until M3 retention/cleanup work.
  • Local login is intentionally convenient: the development link is returned by the API outside production.