@@ -96,7 +96,7 @@ export async function authenticateRequest(
96
96
url . searchParams . append ( constants . QueryParameters . DevBrowser , authenticateContext . devBrowserToken ) ;
97
97
}
98
98
99
- return new Headers ( { location : url . href } ) ;
99
+ return new Headers ( { [ constants . Headers . Location ] : url . href } ) ;
100
100
}
101
101
102
102
async function resolveHandshake ( ) {
@@ -120,7 +120,8 @@ export async function authenticateRequest(
120
120
const newUrl = new URL ( authenticateContext . clerkUrl ) ;
121
121
newUrl . searchParams . delete ( constants . QueryParameters . Handshake ) ;
122
122
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' ) ;
124
125
}
125
126
126
127
if ( sessionToken === '' ) {
@@ -174,6 +175,13 @@ ${error.getFullMessage()}`,
174
175
// Right now the only usage of passing in different headers is for multi-domain sync, which redirects somewhere else.
175
176
// In the future if we want to decorate the handshake redirect with additional headers per call we need to tweak this logic.
176
177
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
+
177
185
// Introduce the mechanism to protect for infinite handshake redirect loops
178
186
// using a cookie and returning true if it's infinite redirect loop or false if we can
179
187
// proceed with triggering handshake.
@@ -294,7 +302,7 @@ ${error.getFullMessage()}`,
294
302
authenticateContext . clerkUrl . toString ( ) ,
295
303
) ;
296
304
297
- const headers = new Headers ( { location : redirectURL . toString ( ) } ) ;
305
+ const headers = new Headers ( { [ constants . Headers . Location ] : redirectURL . toString ( ) } ) ;
298
306
return handleMaybeHandshakeStatus ( authenticateContext , AuthErrorReason . SatelliteCookieNeedsSyncing , '' , headers ) ;
299
307
}
300
308
@@ -314,7 +322,7 @@ ${error.getFullMessage()}`,
314
322
}
315
323
redirectBackToSatelliteUrl . searchParams . append ( constants . QueryParameters . ClerkSynced , 'true' ) ;
316
324
317
- const headers = new Headers ( { location : redirectBackToSatelliteUrl . toString ( ) } ) ;
325
+ const headers = new Headers ( { [ constants . Headers . Location ] : redirectBackToSatelliteUrl . toString ( ) } ) ;
318
326
return handleMaybeHandshakeStatus ( authenticateContext , AuthErrorReason . PrimaryRespondsToSyncing , '' , headers ) ;
319
327
}
320
328
/**
0 commit comments