@@ -96,7 +96,7 @@ export async function authenticateRequest(
9696 url . searchParams . append ( constants . QueryParameters . DevBrowser , authenticateContext . devBrowserToken ) ;
9797 }
9898
99- return new Headers ( { location : url . href } ) ;
99+ return new Headers ( { [ constants . Headers . Location ] : url . href } ) ;
100100 }
101101
102102 async function resolveHandshake ( ) {
@@ -120,7 +120,8 @@ export async function authenticateRequest(
120120 const newUrl = new URL ( authenticateContext . clerkUrl ) ;
121121 newUrl . searchParams . delete ( constants . QueryParameters . Handshake ) ;
122122 newUrl . searchParams . delete ( constants . QueryParameters . HandshakeHelp ) ;
123- headers . append ( 'Location' , newUrl . toString ( ) ) ;
123+ headers . append ( constants . Headers . Location , newUrl . toString ( ) ) ;
124+ headers . set ( constants . Headers . CacheControl , 'no-store' ) ;
124125 }
125126
126127 if ( sessionToken === '' ) {
@@ -174,6 +175,13 @@ ${error.getFullMessage()}`,
174175 // Right now the only usage of passing in different headers is for multi-domain sync, which redirects somewhere else.
175176 // In the future if we want to decorate the handshake redirect with additional headers per call we need to tweak this logic.
176177 const handshakeHeaders = headers ?? buildRedirectToHandshake ( ) ;
178+
179+ // Chrome aggressively caches inactive tabs. If we don't set the header here,
180+ // all 307 redirects will be cached and the handshake will end up in an infinite loop.
181+ if ( handshakeHeaders . get ( constants . Headers . Location ) ) {
182+ handshakeHeaders . set ( constants . Headers . CacheControl , 'no-store' ) ;
183+ }
184+
177185 // Introduce the mechanism to protect for infinite handshake redirect loops
178186 // using a cookie and returning true if it's infinite redirect loop or false if we can
179187 // proceed with triggering handshake.
@@ -294,7 +302,7 @@ ${error.getFullMessage()}`,
294302 authenticateContext . clerkUrl . toString ( ) ,
295303 ) ;
296304
297- const headers = new Headers ( { location : redirectURL . toString ( ) } ) ;
305+ const headers = new Headers ( { [ constants . Headers . Location ] : redirectURL . toString ( ) } ) ;
298306 return handleMaybeHandshakeStatus ( authenticateContext , AuthErrorReason . SatelliteCookieNeedsSyncing , '' , headers ) ;
299307 }
300308
@@ -314,7 +322,7 @@ ${error.getFullMessage()}`,
314322 }
315323 redirectBackToSatelliteUrl . searchParams . append ( constants . QueryParameters . ClerkSynced , 'true' ) ;
316324
317- const headers = new Headers ( { location : redirectBackToSatelliteUrl . toString ( ) } ) ;
325+ const headers = new Headers ( { [ constants . Headers . Location ] : redirectBackToSatelliteUrl . toString ( ) } ) ;
318326 return handleMaybeHandshakeStatus ( authenticateContext , AuthErrorReason . PrimaryRespondsToSyncing , '' , headers ) ;
319327 }
320328 /**
0 commit comments