Require every API route to use authedRoute or publicRoute [ABD-21]
Merged
FR
6d ago+194+194+012345678901234567890123456789-66-66-01234567890123456789
What & why
Third step of ABD-21. Stacked on #721 (base: abd-21-cookie-routes-authed-route); merge that first.
After #720 and #721, most API routes export through authedRoute, but nothing requires it: a new route that forgets auth still passes lint, because no-api-incomplete-signup.grit only flagged the wrong helper (getUserWithMfa), not a missing one. This makes the wrapper mandatory.
publicRoute(handler)(@/lib/http/authed-route): opens an anonymous viewer frame and never authenticates. Used by the deliberately public routes (waitlist,invites/validate,username/check,share-invites,embed/rooms/[roomId]) and the CORS preflightOPTIONShandlers.- Admin routes
admin/stats,admin/users,admin/users/[id]move ontoauthedRoute({ credentials: "session" })and keep their admin check in the handler. Behaviour change: a signed-out caller now gets 401 instead of 403. api-route-wrappers.test.ts(new, unit): fails for a handler exported any way other thanauthedRoute(...)/publicRoute(...), a public route missing from its reviewed list, or a route file resolving the user itself (getUserWithMfa,getCompletedSignupUser,authenticateRequest,withViewer, …).- Deleted
no-api-incomplete-signup.gritand itsbiome.jsonoverride; the new test covers it and more. The isolation suite's runtime viewer-frame check stays. token-route-access.test.tsnow only scans files that importauthedRoute(public routes importpublicRoutefrom the same module).- Agent guidance (
AGENTS.md,app/src/app/AGENTS.md,add-authed-pageskill,withViewerdoc) describes the new rule.
Thread: https://ampcode.com/threads/T-01a1e700-7a74-76b5-85a8-6c3a6faaad6c
Checklist
- User-facing change → added/updated a PostHog event (and a funnel/insight for a new flow), or N/A — N/A, internal refactor
- User-facing or service change → docs updated (README features/roadmap/services,
.env.example, in-app help,CONTRIBUTING.md, onboarding checklist), or N/A — N/A for user docs; agent guidance updated as above - New error paths report via
captureServerException/ the error boundary, or N/A — N/A, no new error paths - New behavior is covered by tests, or N/A —
api-route-wrappers.test.tsis the new guardrail; existing route tests cover the moved routes - User-facing change → demo video attached (
record-pr-demoskill); refactor through a user flow → parity run, or N/A — N/A, API auth plumbing only - If this fixes a recurring defect, considered a guardrail via the
learnskill, or N/A — this is the guardrail: it replaces a narrower grit rule with a test covering every route
Notes
Verified locally:
bun run check:fixclean; full unit suite passes (4,462 tests); integration project 659/659 (placeholder Supabase env values).- Mutation checks on
api-route-wrappers.test.ts: a bare handler,withVieweralone, anexport async function GET, an unlistedpublicRoute, a directgetCompletedSignupUserreference, and an unwrapped aliased export each fail it. token-route-access.test.tsstill fails for an aliasedauthedRouteimport and for a session route switched totokenScope: "read".- Replayed Next's generated route-signature check against all 80 route handlers: passes.