From fdea1bf55aee0a719148d32d3f67309bee6b5a4f Mon Sep 17 00:00:00 2001 From: brkalow Date: Wed, 7 Jan 2026 10:25:14 -0600 Subject: [PATCH] short circuit satellite sync when session cookie is present --- .changeset/cute-frogs-rest.md | 5 +++++ packages/backend/src/tokens/request.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/cute-frogs-rest.md diff --git a/.changeset/cute-frogs-rest.md b/.changeset/cute-frogs-rest.md new file mode 100644 index 00000000000..b473904a939 --- /dev/null +++ b/.changeset/cute-frogs-rest.md @@ -0,0 +1,5 @@ +--- +'@clerk/backend': minor +--- + +Optimzie satellite sync flow to reduce redirects. diff --git a/packages/backend/src/tokens/request.ts b/packages/backend/src/tokens/request.ts index 0061828b026..b2faa3d0acc 100644 --- a/packages/backend/src/tokens/request.ts +++ b/packages/backend/src/tokens/request.ts @@ -461,8 +461,15 @@ export const authenticateRequest: AuthenticateRequest = (async ( } } } + + // Only trigger satellite sync handshake if we don't have session cookies. + // If we have cookies, the client is already linked - fall through to normal + // verification flow which can leverage the refresh flow for expired tokens + // instead of requiring a full multi-domain handshake. + const isLinked = authenticateContext.clientUat && authenticateContext.sessionTokenInCookie; + const isRequestEligibleForMultiDomainSync = - authenticateContext.isSatellite && authenticateContext.secFetchDest === 'document'; + authenticateContext.isSatellite && authenticateContext.secFetchDest === 'document' && !isLinked; /** * Begin multi-domain sync flows