From de231e03e5e1aeded9f91f8cbf497aef0eb07a69 Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 3 Sep 2025 21:44:21 -0500 Subject: [PATCH 1/4] fix(clerk-js): Remove double slash from FAPI client urls --- .../src/core/__tests__/fapiClient.spec.ts | 21 +++++++++++++++++++ packages/clerk-js/src/core/fapiClient.ts | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/clerk-js/src/core/__tests__/fapiClient.spec.ts b/packages/clerk-js/src/core/__tests__/fapiClient.spec.ts index 728b259fe94..7aa96b3368f 100644 --- a/packages/clerk-js/src/core/__tests__/fapiClient.spec.ts +++ b/packages/clerk-js/src/core/__tests__/fapiClient.spec.ts @@ -21,6 +21,13 @@ const fapiClientWithProxy = createFapiClient({ proxyUrl, }); +const proxyUrlWithTrailingSlash = 'https://clerk.com/api/__clerk/'; + +const fapiClientWithProxyTrailingSlash = createFapiClient({ + ...baseFapiClientOptions, + proxyUrl: proxyUrlWithTrailingSlash, +}); + type RecursivePartial = { [P in keyof T]?: RecursivePartial; }; @@ -79,6 +86,20 @@ describe('buildUrl(options)', () => { ); }); + it('returns the correct URL when proxy URL has a trailing slash', () => { + // The expected URL should NOT have double slashes after __clerk + expect(fapiClientWithProxyTrailingSlash.buildUrl({ path: '/foo' }).href).toBe( + `https://clerk.com/api/__clerk/v1/foo?__clerk_api_version=${SUPPORTED_FAPI_VERSION}&_clerk_js_version=test`, + ); + }); + + it('handles complex paths correctly with proxy URL with trailing slash', () => { + const path = '/client/sign_ins/sia_123/prepare_first_factor'; + expect(fapiClientWithProxyTrailingSlash.buildUrl({ path }).href).toBe( + `https://clerk.com/api/__clerk/v1${path}?__clerk_api_version=${SUPPORTED_FAPI_VERSION}&_clerk_js_version=test`, + ); + }); + it('uses domain from options if production', () => { expect( createFapiClient({ ...baseFapiClientOptions, domain: 'clerk.other.com', instanceType: 'production' }).buildUrl({ diff --git a/packages/clerk-js/src/core/fapiClient.ts b/packages/clerk-js/src/core/fapiClient.ts index d12cce9a181..79939740a18 100644 --- a/packages/clerk-js/src/core/fapiClient.ts +++ b/packages/clerk-js/src/core/fapiClient.ts @@ -149,7 +149,11 @@ export function createFapiClient(options: FapiClientOptions): FapiClient { if (options.proxyUrl) { const proxyBase = new URL(options.proxyUrl); - const proxyPath = proxyBase.pathname.slice(1, proxyBase.pathname.length); + // Remove leading slash and any trailing slash from the proxy pathname + let proxyPath = proxyBase.pathname.slice(1); + if (proxyPath.endsWith('/')) { + proxyPath = proxyPath.slice(0, -1); + } return buildUrlUtil( { base: proxyBase.origin, From a7151133cb328bd2627c7eca86d4298f1e4aa3ad Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 3 Sep 2025 21:45:00 -0500 Subject: [PATCH 2/4] wip --- packages/clerk-js/src/core/fapiClient.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/clerk-js/src/core/fapiClient.ts b/packages/clerk-js/src/core/fapiClient.ts index 79939740a18..2207aca0251 100644 --- a/packages/clerk-js/src/core/fapiClient.ts +++ b/packages/clerk-js/src/core/fapiClient.ts @@ -149,7 +149,6 @@ export function createFapiClient(options: FapiClientOptions): FapiClient { if (options.proxyUrl) { const proxyBase = new URL(options.proxyUrl); - // Remove leading slash and any trailing slash from the proxy pathname let proxyPath = proxyBase.pathname.slice(1); if (proxyPath.endsWith('/')) { proxyPath = proxyPath.slice(0, -1); From 03a2171a2a8272c6c497d73cc2c148780f07f346 Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 3 Sep 2025 21:57:29 -0500 Subject: [PATCH 3/4] changeset --- .changeset/fluffy-comics-peel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fluffy-comics-peel.md diff --git a/.changeset/fluffy-comics-peel.md b/.changeset/fluffy-comics-peel.md new file mode 100644 index 00000000000..510c43dd7c0 --- /dev/null +++ b/.changeset/fluffy-comics-peel.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-js': patch +--- + +Fixing an issue where an incorrect FAPI client URLs were generated in an app using a proxy configuration. From 418b448fd01943a0e92e8e6cccf84c2e452e393d Mon Sep 17 00:00:00 2001 From: Jacek Radko Date: Wed, 3 Sep 2025 22:05:12 -0500 Subject: [PATCH 4/4] Update .changeset/fluffy-comics-peel.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .changeset/fluffy-comics-peel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fluffy-comics-peel.md b/.changeset/fluffy-comics-peel.md index 510c43dd7c0..8531c19d220 100644 --- a/.changeset/fluffy-comics-peel.md +++ b/.changeset/fluffy-comics-peel.md @@ -2,4 +2,4 @@ '@clerk/clerk-js': patch --- -Fixing an issue where an incorrect FAPI client URLs were generated in an app using a proxy configuration. +Fix double slash in FAPI client URLs when using a proxy configuration (avoids 308 redirects).