chore(fastify): Use runtime keys for auth client and explicit opt-out handshake option#8560
chore(fastify): Use runtime keys for auth client and explicit opt-out handshake option#8560jescalan wants to merge 16 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
🦋 Changeset detectedLatest commit: 8f24d90 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
!snapshot |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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 (2)
📝 WalkthroughWalkthroughThis PR initializes a single Clerk client at middleware setup using resolved runtime keys, adds an optional enableHandshake flag to control handshake/redirect handling, strips handshake cookies/query params when disabled, and attaches the Clerk client to requests as request.clerk. Type declarations and the plugin decoration are updated accordingly, and tests were added to verify runtime key usage, enableHandshake behavior, handshake cookie stripping, and request.clerk exposure. Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 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. Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
This comment has been minimized.
This comment has been minimized.
@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: |
71d3ff7 to
25efe99
Compare
|
Done — I pulled in the changes from #8563 in commits 19f3473, 0cc1e3c, and 60312d1, and added a follow-up fix for the React Router CI type error in 9243a0a. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
It looks like Quick solution: strip/ignore cookies/queries when the config is |
|
!snapshot |
This comment has been minimized.
This comment has been minimized.
|
@jorgevrgs thanks, generated another snapshot for you
|
|
!snapshot |
|
Hey @wobsoriano - the snapshot version command generated the following package versions:
Tip: Use the snippet copy button below to quickly install the required packages. npm i @clerk/astro@3.2.5-snapshot.v20260522175603 --save-exact
npm i @clerk/backend@3.4.10-snapshot.v20260522175603 --save-exact
npm i @clerk/chrome-extension@3.1.27-snapshot.v20260522175603 --save-exact
npm i @clerk/clerk-js@6.11.2-snapshot.v20260522175603 --save-exact
npm i @clerk/dev-cli@0.1.1-snapshot.v20260522175603 --save-exact
npm i @clerk/expo@3.2.13-snapshot.v20260522175603 --save-exact
npm i @clerk/expo-passkeys@1.0.26-snapshot.v20260522175603 --save-exact
npm i @clerk/express@2.1.18-snapshot.v20260522175603 --save-exact
npm i @clerk/fastify@3.1.28-snapshot.v20260522175603 --save-exact
npm i @clerk/hono@0.1.28-snapshot.v20260522175603 --save-exact
npm i @clerk/localizations@4.6.5-snapshot.v20260522175603 --save-exact
npm i @clerk/msw@0.0.26-snapshot.v20260522175603 --save-exact
npm i @clerk/nextjs@7.3.6-snapshot.v20260522175603 --save-exact
npm i @clerk/nuxt@2.4.5-snapshot.v20260522175603 --save-exact
npm i @clerk/react@6.6.5-snapshot.v20260522175603 --save-exact
npm i @clerk/react-router@3.2.6-snapshot.v20260522175603 --save-exact
npm i @clerk/shared@4.12.1-snapshot.v20260522175603 --save-exact
npm i @clerk/tanstack-react-start@1.2.6-snapshot.v20260522175603 --save-exact
npm i @clerk/testing@2.0.30-snapshot.v20260522175603 --save-exact
npm i @clerk/ui@1.11.1-snapshot.v20260522175603 --save-exact
npm i @clerk/upgrade@2.0.3-snapshot.v20260522175603 --save-exact
npm i @clerk/vue@2.2.5-snapshot.v20260522175603 --save-exact |
Summary
authenticateRequestContext
Forced handshake nonce transport stores a short
__clerk_handshake_nonceinstead of the large__clerk_handshakepayload. Server SDKs then need to exchange that nonce through the Backend API client attached toauthenticateRequest.Several framework wrappers passed runtime
secretKey/publishableKeyintoauthenticateRequest, but constructed the request client from environment defaults or earlier unresolved options. That means apps loading keys asynchronously and passing them into middleware could authenticate some paths with the runtime key while nonce payload exchange still used a client created without that key.Hono and Next.js already build the client from runtime options, so no patch was needed there.
Performance
This patch avoids adding a new per-request client construction path in the common static-key cases:
clerkPlugin()registers middleware.clerkMiddleware()is created for static options. The callback form can still create a middleware/client per request, but that was already how callback options worked.createClerkClient()itself does not perform network I/O; it builds the Backend API resource client,authenticateRequestclosure, and telemetry collector. The nonce exchange network call only happens whenauthenticateRequestreaches forced handshake nonce handling.Testing
pnpm -C packages/fastify exec vitest run src/__tests__/withClerkMiddleware.test.tspnpm -C packages/express exec vitest run src/__tests__/clerkMiddleware.test.ts -t "builds a per-middleware ClerkClient with runtime keys"pnpm -C packages/react-router exec vitest run src/server/__tests__/clerkMiddleware.test.tspnpm -C packages/nuxt exec vitest run src/runtime/server/__tests__/clerkClient.test.tspnpm -C packages/astro exec vitest run src/server/__tests__/clerk-client.test.tspnpm -C packages/tanstack-react-start exec vitest run src/server/__tests__/clerkClient.test.tspnpm -C packages/fastify buildpnpm -C packages/express buildpnpm -C packages/fastify lint(passes with existing no-misused-promises warnings)pnpm -C packages/express lint(passes with existing no-misused-promises warnings)pnpm -C packages/astro lint(passes with existing warnings)git diff --checkNotes
getAutoProxyUrlFromEnvironment is not a function.@clerk/react/@clerk/vueexports or declarations). Their JS builds reached the compile stage before those existing declaration/linkage failures.