Repository navigation
Recommend protecting auth close to the resource - #3426
Merged
Merged
Conversation
Reframe middleware-based auth gating as no longer recommended in favor of checks close to the resource. Adds a shared partial, a 'Migrating from middleware checks' section to protect-pages, swaps createRouteMatcher patterns to :path*, and softens the clerk-middleware reference callouts to 'no longer recommended'.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
jacekradko
marked this pull request as ready for review
June 8, 2026 14:34
Lead with the recommendation (protect access as close to the resource as possible) instead of demoting middleware gating. Downgrades the callouts from WARNING to TIP/NOTE, drops the 'no longer recommended'/'wrong layer'/'can fail to apply' framing, renames the protect-pages section to 'Why protect close to the resource?', and keeps clerkMiddleware() explicitly supported for non-auth work.
State plainly that clerkMiddleware() is required and is the right place for redirects/headers, without 'still'/'remains'/'fully supported' that presuppose a prior state.
Remove the 'rather than gating in middleware / keeps the check in sync' tail on the satellite-domains note, strengthen the onboarding callout to a direct 'enforce at the resource' IMPORTANT, and drop 'still' from the sign-in public-route note.
Drop the 'rather than in your middleware' intro tail, the 'no resource-level equivalent that is also a security boundary' concession, the 'a layout can still handle the redirect, but' hedge, the 'no codemod or lint rule yet' line, and flatten the 'works, but' comparison in the Why section.
…nd auth reference
This was referenced Jun 8, 2026
…vel protection
Restructure clerk-middleware.mdx: reframe createRouteMatcher() to non-auth
route matching and replace the auth-gating sections (Protect routes, multiple
groups, all routes, token types) with one Protecting routes pointer to
protect-pages / authorization-checks / auth({ acceptsToken }). Drop the
middleware option from basic-rbac, the !isPublicRoute sections from the custom
sign-in/up guides, and repoint the verifying-* token-type links to the route
handler approach.
added 3 commits
June 30, 2026 14:57
…ce, not a security boundary
…clerk/nextjs #8994); keep middleware-auth-gating as editorial
…uireAuth into reading.astro per Alexis's #3407 direction
added 2 commits
July 1, 2026 18:30
…ore-2, session-tasks, mcp, and clerk-middleware notices
- fix incremental flow: narrow middleware patterns per slice instead of removing all checks mid-migration; note double protection is safe - expand Pages Router warning to cover pages/api handlers and Bulk Fixer non-applicability - warn manual migrators about the isPublicRoute inversion pattern - add URL-pattern to folder-glob conversion table (route groups, [locale]) and the silent no-match failure mode - state deprecation mechanics: behavior unchanged, one-time dev warning, removed next major (per clerk/javascript #8994) - state ESLint >=9 flat-config prereq and experimental/pin advice - keep config.matcher in 'after' proxy.ts snippets; point non-auth createRouteMatcher uses at native matching - protect-content: auth.protect() in a Server Action returns a 401, not a redirect (matches SDK protect.ts) - app-router/auth: add the Server Action 401 case to the behavior callout - dedupe auth.protect() behavior sentence and Bulk Fixer description into shared partials
…ion check, astro import + redirect target Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
|
Pushed some review fixes directly in 3c51752.
|
alexisintech
approved these changes
Jul 1, 2026
alexisintech
left a comment
Contributor
There was a problem hiding this comment.
alrightyyy I think this is ready to ship 🙏
…ssues - nuxt clerk-middleware: match on getRequestURL(event).pathname; event.path includes the query string, so /api/admin?page=2 bypassed the new matchesRoute examples entirely - build-mcp-server: make shared prose tool-name-neutral (next uses get-clerk-user-data, express uses get_clerk_user_data per clerk/mcp-tools); fix mark highlight ranges that ran past both code blocks - reading: add null guards after currentUser() (typed User | null, examples failed strict typecheck) - use-auth/use-user partials: tanstack filename app/routes -> src/routes to match the quickstart and same-page examples - reading.astro: API route filename src/api -> src/pages/api (Astro only serves endpoints under src/pages) - astro clerk-middleware: reword :path* NOTE with framework-neutral rationale
…-resource-guidance # Conflicts: # docs/guides/ai/mcp/build-mcp-server.mdx
…-resource-guidance # Conflicts: # docs/_partials/nextjs/next-steps.mdx # docs/getting-started/quickstart.nuxt.mdx
5 of 9 tasks
SarahSoutoul
pushed a commit
that referenced
this pull request
Jul 6, 2026
Co-authored-by: Alexis Aguilar <[email protected]> Co-authored-by: Fredrik Höglund <[email protected]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stops recommending middleware as the place to gate auth and points protection at the resource that reads the data (the page, Route Handler, Server Action, or endpoint). The copyable
createRouteMatcher()+auth.protect()/!isPublicRouteallowlist examples come out of the guides and references;clerkMiddleware()stays documented for its non-auth uses (redirects, headers, geo, route matching).This began as Next.js-only and now also folds in the Astro, Nuxt, and Core-2 upgrade-guide versions that were open as separate PRs (#3404-3408, now closed). The old pattern survives on purpose in the renamed canonical guide
protect-content(wasprotect-pages), which gains a "migrating from middleware-based auth checks" walkthrough: before/after, therequireUser()/requireAuth()helper, and the add-first-remove-last ordering for inverting!isPublicRoute. That guide and the per-SDKreading.*pages that host the helper are the content worth real review.The deprecation wording is deliberately uneven and worth checking: Next.js and Astro call
createRouteMatcher()"deprecated" because their SDKs log a runtime warning (Astro shipped it in v3.4.8; Next.js ships it in clerk/javascript#8994), while Nuxt only says "no longer recommended" since its SDK hasn't deprecated the helper. Because of the Next.js side, this has to merge together with clerk/javascript#8994, or the docs assert a deprecation that isn't live yet.One separable rider remains if you'd rather split it: the
use-authreference/partial consolidation.