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