Skip to content

fix(express): forward all auth options to authenticateRequest#8370

Draft
jacekradko wants to merge 1 commit intomainfrom
jacek/express-forward-auth-options
Draft

fix(express): forward all auth options to authenticateRequest#8370
jacekradko wants to merge 1 commit intomainfrom
jacek/express-forward-auth-options

Conversation

@jacekradko
Copy link
Copy Markdown
Member

Summary

Follow-up to #8287. That PR fixed clockSkewInMs being silently dropped in @clerk/express's middleware. This addresses the class of bug — not just that one field.

packages/express/src/authenticateRequest.ts was re-destructuring a hand-picked subset of ClerkMiddlewareOptions (= AuthenticateRequestOptions & VerifyTokenOptions) and passing only those fields to clerkClient.authenticateRequest(). Everything not explicitly listed was accepted by the TypeScript types and silently ignored at runtime. Fields that were still being dropped:

  • From AuthenticateRequestOptions: organizationSyncOptions, signUpUrl, afterSignInUrl, afterSignUpUrl, satelliteAutoSync
  • From VerifyJwtOptions: headerType
  • From LoadClerkJWKFromRemoteOptions: skipJwksCache, apiUrl, apiVersion

Approach

Spread the full options object through to clerkClient.authenticateRequest(), peeling off:

  • Middleware-only keys that aren't valid on the backend call (clerkClient, debug, frontendApiProxy)
  • The few fields that need middleware-side resolution against env/URL (isSatellite, domain, signInUrl, proxyUrl, secretKey, machineSecretKey, publishableKey), which are then re-applied after resolution

New options added to AuthenticateRequestOptions / VerifyTokenOptions in the future flow through without another edit here.

Scope notes

  • Does not address the separate customer-reported issue of session.getToken() returning a 20h-stale JWT on the client — that's unrelated to the middleware option plumbing (20h is far beyond any clockSkewInMs value).
  • Opening as draft — would appreciate a look at whether ClerkMiddlewareOptions should be narrowed at the type level instead (so middleware-only keys don't structurally overlap with AuthenticateRequestOptions in the first place). Happy to take that on in this PR if preferred.

Test plan

  • New regression test: arbitrary AuthenticateRequestOptions / VerifyTokenOptions (organizationSyncOptions, skipJwksCache, headerType, audience, authorizedParties, jwtKey, acceptsToken) are forwarded
  • New regression test: middleware-only options (clerkClient, debug, frontendApiProxy) are not forwarded
  • Existing clockSkewInMs regression test still passes
  • `pnpm turbo run test --filter=@clerk/express` — 32 passed
  • `pnpm turbo run build --filter=@clerk/express` — success

Spread the full options object through to clerkClient.authenticateRequest()
instead of re-destructuring a hand-picked subset. This closes the class of
bug where fields accepted by the ClerkMiddlewareOptions type (e.g.
organizationSyncOptions, skipJwksCache, headerType) were silently ignored
at runtime — same shape as the clockSkewInMs issue fixed in #8287.

Middleware-only keys (clerkClient, debug, frontendApiProxy) are peeled off
so they don't leak into the backend call.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Apr 21, 2026 11:25pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 21, 2026

🦋 Changeset detected

Latest commit: ab71710

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/express Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant