Problem
Modern Next.js (13+) apps concentrate sensitive mutations in Server Actions ('use server'), which AuthMap currently detects but does not analyze at all — arguably the largest single blind spot for the Next.js adapter, since these functions mutate data with no route-level auth in front of them. Additionally, route groups (group) and parallel routes @slot are standard App Router layout conventions, and auth enforced in a parent layout.tsx is a common protection pattern that is currently invisible.
Current behavior
- Files containing
'use server' emit nextjs_server_action_not_analyzed and return no routes or evidence (crates/authmap-adapters/src/nextjs.rs, early in analyze).
route_path_for_file (crates/authmap-adapters/src/nextjs.rs) converts file paths to URL paths with no special handling for (group) or @slot segments.
- Auth helpers are recognized from a hardcoded list (
NEXTJS_MIDDLEWARE_AUTH_HELPERS: getServerSession/auth/getAuth/currentUser/clerk/etc.); custom wrappers fall through.
- Layouts are not inspected; only
route.ts handlers, pages/api/**, and middleware.ts matchers.
Proposed implementation
- Server Actions
- Inventory exported async functions in
'use server' files (and inline 'use server' function bodies) as routes of a new kind (e.g., kind: "server_action", method ACTION, path = module path + export name). This requires a route-kind/method extension in authmap-core — update schemas/ and docs/SCHEMA.md accordingly, and gate JSON consumers via the documented contract (docs/JSON_CONSUMERS.md).
- Extract auth evidence from action bodies using the existing auth-helper rules (
getServerSession, auth(), currentUser, clerk helpers...) — same matching used for route handlers; ORM mutation extraction (Prisma etc.) already works on function bodies, enabling action→mutation linking for free.
- Replace
nextjs_server_action_not_analyzed with per-action analysis; keep a diagnostic for dynamic/unresolvable action exports.
- Route groups and parallel routes
- In
route_path_for_file: strip (group) segments from the URL path (they do not affect the URL) while retaining them in route metadata; strip @slot segments similarly and flag with a low-severity note. Add nextjs_unusual_route_segment coverage where conventions are ambiguous (intercepting routes (.), (..)).
- Layout-level auth inheritance
- When a
layout.tsx in a segment (or a (group) directory) calls a recognized auth helper with a redirect/guard shape, emit inherited, lower-confidence evidence for routes and pages beneath that segment. Record the layout file in the evidence rationale so reviewers can verify.
- Extensible auth-helper list
- Allow config custom rules (
crates/authmap-config) to extend NEXTJS_MIDDLEWARE_AUTH_HELPERS so projects with wrapper helpers (requireUser, withAuth) classify correctly without code changes. (Complements the cross-framework synonym work tracked separately.)
Acceptance criteria
References
docs/PARSERS_AND_ADAPTERS.md Next.js limitations paragraph
crates/authmap-adapters/src/nextjs.rs (route_path_for_file, NEXTJS_MIDDLEWARE_AUTH_HELPERS, server-action diagnostic emission)
docs/SCHEMA.md, docs/JSON_CONSUMERS.md for the schema-impacting route kind
Problem
Modern Next.js (13+) apps concentrate sensitive mutations in Server Actions (
'use server'), which AuthMap currently detects but does not analyze at all — arguably the largest single blind spot for the Next.js adapter, since these functions mutate data with no route-level auth in front of them. Additionally, route groups(group)and parallel routes@slotare standard App Router layout conventions, and auth enforced in a parentlayout.tsxis a common protection pattern that is currently invisible.Current behavior
'use server'emitnextjs_server_action_not_analyzedand return no routes or evidence (crates/authmap-adapters/src/nextjs.rs, early inanalyze).route_path_for_file(crates/authmap-adapters/src/nextjs.rs) converts file paths to URL paths with no special handling for(group)or@slotsegments.NEXTJS_MIDDLEWARE_AUTH_HELPERS: getServerSession/auth/getAuth/currentUser/clerk/etc.); custom wrappers fall through.route.tshandlers,pages/api/**, andmiddleware.tsmatchers.Proposed implementation
'use server'files (and inline'use server'function bodies) as routes of a new kind (e.g.,kind: "server_action", methodACTION, path = module path + export name). This requires a route-kind/method extension inauthmap-core— updateschemas/anddocs/SCHEMA.mdaccordingly, and gate JSON consumers via the documented contract (docs/JSON_CONSUMERS.md).getServerSession,auth(),currentUser, clerk helpers...) — same matching used for route handlers; ORM mutation extraction (Prisma etc.) already works on function bodies, enabling action→mutation linking for free.nextjs_server_action_not_analyzedwith per-action analysis; keep a diagnostic for dynamic/unresolvable action exports.route_path_for_file: strip(group)segments from the URL path (they do not affect the URL) while retaining them in route metadata; strip@slotsegments similarly and flag with a low-severity note. Addnextjs_unusual_route_segmentcoverage where conventions are ambiguous (intercepting routes(.),(..)).layout.tsxin a segment (or a(group)directory) calls a recognized auth helper with a redirect/guard shape, emit inherited, lower-confidence evidence for routes and pages beneath that segment. Record the layout file in the evidence rationale so reviewers can verify.crates/authmap-config) to extendNEXTJS_MIDDLEWARE_AUTH_HELPERSso projects with wrapper helpers (requireUser,withAuth) classify correctly without code changes. (Complements the cross-framework synonym work tracked separately.)Acceptance criteria
(marketing)/(app)route-group fixture produces correct URL paths; parallel-route fixture does not produce bogus paths.docs/PARSERS_AND_ADAPTERS.mdNext.js Not yet list anddocs/DIAGNOSTICS.mdupdated; CHANGELOG entry.References
docs/PARSERS_AND_ADAPTERS.mdNext.js limitations paragraphcrates/authmap-adapters/src/nextjs.rs(route_path_for_file,NEXTJS_MIDDLEWARE_AUTH_HELPERS, server-action diagnostic emission)docs/SCHEMA.md,docs/JSON_CONSUMERS.mdfor the schema-impacting route kind