refactor(nextjs): factor runHandlerWithRequestState out of baseNextMiddleware#8368
refactor(nextjs): factor runHandlerWithRequestState out of baseNextMiddleware#8368jacekradko wants to merge 1 commit intomainfrom
Conversation
…ddleware Extracts the post-authentication pipeline (handler invocation, CSP, redirects, response decoration) into a private helper. Also adds createBootstrapSignedOutState to @clerk/backend/internal for synthesizing a signed-out RequestState without a publishable key — intended for framework integrations that must run authorization logic before real Clerk keys are available (e.g. the Next.js keyless bootstrap window). Pure refactor — no behavioral change.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 98d26f7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThis pull request introduces a new Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Detailed analysisFeature addition (backend):
Refactoring (nextjs):
Review focus areas:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
Summary
Groundwork for SDK-70. Pure refactor — no behavioral change.
@clerk/backend— exports a newcreateBootstrapSignedOutStatehelper from@clerk/backend/internal. Returns a syntheticUnauthenticatedState<'session_token'>without requiring a publishable key or anAuthenticateContext. Intended for framework integrations that need to run authorization logic before real Clerk keys are available (e.g. the Next.js keyless bootstrap window).@clerk/nextjs— factors the post-authentication pipeline insidebaseNextMiddleware(handler invocation, CSP, redirects, response decoration) into a privaterunHandlerWithRequestStatehelper. TheauthenticateRequestcall and subsequent pipeline now live in a single, testable unit, making it possible for a follow-up to feed a synthesizedRequestStateinto the same pipeline when there's no real publishable key yet.Why split this PR?
The follow-up (SDK-70 proper) will flip
keylessMiddleware's no-key branch to synthesize a signed-out state and run the user's middleware handler, closing a middleware-bypass window during the keyless bootstrap. That change is small on its own — most of the work is the plumbing to route a non-authenticateRequest-producedRequestStatethrough the same post-auth pipeline. Landing the plumbing first keeps the behavioral change's diff small and reviewable.Test plan
pnpm turbo build --filter=@clerk/backend --filter=@clerk/nextjspassespnpm --filter=@clerk/backend test— 1186/1186 pass (includes the updatedexports.test.tssnapshot)pnpm --filter=@clerk/nextjs test— 369 pass / 50 fail; all 50 failures are a pre-existingAbortSignal/createClerkRequesttest-env issue that reproduces identically onmain(unrelated to this refactor)baseNextMiddlewarewere preserved)