feat(backend): support configurable Frontend API proxy URLs#9223
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 20728fb 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 |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-google-signin
@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: |
📝 WalkthroughWalkthroughThe backend proxy adds an optional Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/backend/src/__tests__/proxy.test.ts`:
- Around line 238-252: Expand the invalid FAPI URL tests around
clerkFrontendApiProxy to cover URLs containing credentials, query strings, and
fragments, plus an invalid CLERK_FAPI_URL configuration. Assert each returns
status 500 with the configuration error response and that mockFetch is not
called, preserving the existing unsupported-scheme coverage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: f5bf50f0-f358-4326-b810-5780be707f09
📒 Files selected for processing (5)
.changeset/bright-pandas-proxy.mdpackages/backend/src/__tests__/proxy.test.tspackages/backend/src/proxy.tspackages/nextjs/src/server/__tests__/proxy.test.tspackages/nextjs/src/server/proxy.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
clerk/clerk_go(manual)
API Changes Report
Summary
@clerk/backendCurrent version: 3.12.0 Subpath
|
- Add fapiUrl support to backend and Next.js proxy helpers, including CLERK_FAPI_URL fallback, URL validation, and trailing-slash normalization for lower-environment FAPI targets.
7880501 to
20728fb
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/backend/src/__tests__/proxy.test.ts`:
- Around line 224-236: Update the test “uses CLERK_FAPI_URL when no FAPI URL is
configured” to set CLERK_FAPI_URL with a trailing slash, while retaining the
expected fetch URL without a double slash. Keep the test focused on the
environment fallback path and leave the direct fapiUrl behavior unchanged.
- Around line 207-222: Update the public Next.js middleware options
documentation and delegated proxy-properties partial to include the new fapiUrl
option, describing its purpose and configuration behavior consistently with
clerkFrontendApiProxy and its existing options. Ensure the option appears in
both documented locations so the supported API is discoverable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 7efa56d8-dd6f-4b85-a9e9-66faf7484fe1
📒 Files selected for processing (5)
.changeset/bright-pandas-proxy.mdpackages/backend/src/__tests__/proxy.test.tspackages/backend/src/proxy.tspackages/nextjs/src/server/__tests__/proxy.test.tspackages/nextjs/src/server/proxy.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
clerk/clerk_go(manual)clerk/dashboard(manual)clerk/accounts(manual)clerk/backoffice(manual)clerk/clerk(manual)clerk/clerk-docs(manual)clerk/cloudflare-workers(manual)
🚧 Files skipped from review as they are similar to previous changes (3)
- .changeset/bright-pandas-proxy.md
- packages/nextjs/src/server/proxy.ts
- packages/backend/src/proxy.ts
| it('uses the configured FAPI URL over CLERK_FAPI_URL and the publishable key', async () => { | ||
| process.env.CLERK_FAPI_URL = 'https://frontend-api.clerkstage.dev'; | ||
| mockFetch.mockResolvedValue(new Response(JSON.stringify({ client: {} }), { status: 200 })); | ||
|
|
||
| const request = new Request('https://example.com/__clerk/v1/client'); | ||
|
|
||
| await clerkFrontendApiProxy(request, { | ||
| publishableKey: 'pk_test_Y2xlcmsuZXhhbXBsZS5jb20k', | ||
| secretKey: 'sk_test_xxx', | ||
| fapiUrl: 'http://localhost:8001/', | ||
| }); | ||
|
|
||
| const [url, options] = mockFetch.mock.calls[0]; | ||
| expect(url).toBe('http://localhost:8001/v1/client'); | ||
| expect(options.headers.get('Host')).toBe('localhost:8001'); | ||
| }); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Document the new public fapiUrl option.
The linked Next.js middleware options table and delegated proxy-properties partial do not expose fapiUrl, leaving the new supported configuration undiscoverable. Update those docs alongside this API addition. As per coding guidelines, “Update documentation for API changes.”
🧰 Tools
🪛 Betterleaks (1.6.1)
[high] 214-214: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/backend/src/__tests__/proxy.test.ts` around lines 207 - 222, Update
the public Next.js middleware options documentation and delegated
proxy-properties partial to include the new fapiUrl option, describing its
purpose and configuration behavior consistently with clerkFrontendApiProxy and
its existing options. Ensure the option appears in both documented locations so
the supported API is discoverable.
Sources: Coding guidelines, Linked repositories
| it('uses CLERK_FAPI_URL when no FAPI URL is configured', async () => { | ||
| process.env.CLERK_FAPI_URL = 'https://frontend-api.clerkstage.dev'; | ||
| mockFetch.mockResolvedValue(new Response(JSON.stringify({ client: {} }), { status: 200 })); | ||
|
|
||
| const request = new Request('https://example.com/__clerk/v1/client'); | ||
|
|
||
| await clerkFrontendApiProxy(request, { | ||
| publishableKey: 'pk_test_Y2xlcmsuZXhhbXBsZS5jb20k', | ||
| secretKey: 'sk_test_xxx', | ||
| }); | ||
|
|
||
| expect(mockFetch.mock.calls[0][0]).toBe('https://frontend-api.clerkstage.dev/v1/client'); | ||
| }); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Cover trailing-slash normalization for CLERK_FAPI_URL.
This only verifies an environment URL without a trailing slash. Use https://frontend-api.clerkstage.dev/ here and retain the no-double-slash assertion, so the environment fallback contract is protected independently of the direct fapiUrl path.
🧰 Tools
🪛 Betterleaks (1.6.1)
[high] 231-231: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/backend/src/__tests__/proxy.test.ts` around lines 224 - 236, Update
the test “uses CLERK_FAPI_URL when no FAPI URL is configured” to set
CLERK_FAPI_URL with a trailing slash, while retaining the expected fetch URL
without a double slash. Keep the test focused on the environment fallback path
and leave the direct fapiUrl behavior unchanged.
Source: Coding guidelines
wobsoriano
left a comment
There was a problem hiding this comment.
kk this looks good, dont see any regressions
CLERK_FAPI_URL fallback, URL validation, and trailing-slash normalization
for lower-environment FAPI targets.
This allows helpers like
clerkFrontendApiProxyandcreateFrontendApiProxyHandlersto target different FAPIs.Description
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change