@@ -20,7 +20,9 @@ export type LoadResourcesOptions = {
20
20
loadOrganization ?: boolean ;
21
21
} ;
22
22
23
- export type RequiredVerifyTokenOptions = Required < Pick < VerifyTokenOptions , 'apiKey' | 'apiUrl' | 'apiVersion' > > ;
23
+ export type RequiredVerifyTokenOptions = Required <
24
+ Pick < VerifyTokenOptions , 'apiKey' | 'secretKey' | 'apiUrl' | 'apiVersion' >
25
+ > ;
24
26
25
27
export type OptionalVerifyTokenOptions = Partial <
26
28
Pick < VerifyTokenOptions , 'authorizedParties' | 'clockSkewInSeconds' | 'jwksCacheTtlInMs' | 'skipJwksCache' | 'jwtKey' >
@@ -192,6 +194,7 @@ export async function authenticateRequest(options: AuthenticateRequestOptions):
192
194
193
195
const {
194
196
apiKey,
197
+ secretKey,
195
198
apiUrl,
196
199
apiVersion,
197
200
cookieToken,
@@ -203,7 +206,12 @@ export async function authenticateRequest(options: AuthenticateRequestOptions):
203
206
loadOrganization,
204
207
} = options ;
205
208
206
- const { sessions, users, organizations } = createBackendApiClient ( { apiKey, apiUrl, apiVersion } ) ;
209
+ const { sessions, users, organizations } = createBackendApiClient ( {
210
+ apiKey,
211
+ secretKey,
212
+ apiUrl,
213
+ apiVersion,
214
+ } ) ;
207
215
208
216
const [ sessionResp , userResp , organizationResp ] = await Promise . all ( [
209
217
loadSession ? sessions . getSession ( sessionId ) : Promise . resolve ( undefined ) ,
@@ -222,6 +230,7 @@ export async function authenticateRequest(options: AuthenticateRequestOptions):
222
230
sessionClaims ,
223
231
{
224
232
apiKey,
233
+ secretKey,
225
234
apiUrl,
226
235
apiVersion,
227
236
token : cookieToken || headerToken || '' ,
@@ -289,8 +298,9 @@ export async function authenticateRequest(options: AuthenticateRequestOptions):
289
298
// prevent interstitial rendering
290
299
// In production, script requests will be missing both uat and session cookies, which will be
291
300
// automatically treated as signed out. This exception is needed for development, because the any // missing uat throws an interstitial in development.
292
- const nonBrowserRequestInDevRule : InterstitialRule = ( { apiKey, userAgent } ) => {
293
- if ( isDevelopmentFromApiKey ( apiKey ) && ! userAgent ?. startsWith ( 'Mozilla/' ) ) {
301
+ const nonBrowserRequestInDevRule : InterstitialRule = ( { apiKey, secretKey, userAgent } ) => {
302
+ const key = secretKey || apiKey ;
303
+ if ( isDevelopmentFromApiKey ( key ) && ! userAgent ?. startsWith ( 'Mozilla/' ) ) {
294
304
return signedOut ( RequestErrorReason . HeaderMissingNonBrowser ) ;
295
305
}
296
306
return undefined ;
@@ -319,8 +329,10 @@ export async function authenticateRequest(options: AuthenticateRequestOptions):
319
329
return undefined ;
320
330
} ;
321
331
322
- const potentialFirstLoadInDevWhenUATMissing : InterstitialRule = ( { apiKey, clientUat } ) => {
323
- const res = isDevelopmentFromApiKey ( apiKey ) ;
332
+ const potentialFirstLoadInDevWhenUATMissing : InterstitialRule = ( { apiKey, secretKey, clientUat } ) => {
333
+ const key = secretKey || apiKey ;
334
+
335
+ const res = isDevelopmentFromApiKey ( key ) ;
324
336
if ( res && ! clientUat ) {
325
337
return interstitial ( RequestErrorReason . CookieUATMissing ) ;
326
338
}
@@ -329,6 +341,7 @@ export async function authenticateRequest(options: AuthenticateRequestOptions):
329
341
330
342
const potentialRequestAfterSignInOrOurFromClerkHostedUiInDev : InterstitialRule = ( {
331
343
apiKey,
344
+ secretKey,
332
345
referrer,
333
346
host,
334
347
forwardedHost,
@@ -338,15 +351,23 @@ export async function authenticateRequest(options: AuthenticateRequestOptions):
338
351
const crossOriginReferrer =
339
352
referrer &&
340
353
checkCrossOrigin ( { originURL : new URL ( referrer ) , host, forwardedHost, forwardedPort, forwardedProto } ) ;
354
+ const key = secretKey || apiKey ;
341
355
342
- if ( isDevelopmentFromApiKey ( apiKey ) && crossOriginReferrer ) {
356
+ if ( isDevelopmentFromApiKey ( key ) && crossOriginReferrer ) {
343
357
return interstitial ( RequestErrorReason . CrossOriginReferrer ) ;
344
358
}
345
359
return undefined ;
346
360
} ;
347
361
348
- const potentialFirstRequestOnProductionEnvironment : InterstitialRule = ( { apiKey, clientUat, cookieToken } ) => {
349
- if ( isProductionFromApiKey ( apiKey ) && ! clientUat && ! cookieToken ) {
362
+ const potentialFirstRequestOnProductionEnvironment : InterstitialRule = ( {
363
+ apiKey,
364
+ secretKey,
365
+ clientUat,
366
+ cookieToken,
367
+ } ) => {
368
+ const key = secretKey || apiKey ;
369
+
370
+ if ( isProductionFromApiKey ( key ) && ! clientUat && ! cookieToken ) {
350
371
return signedOut ( RequestErrorReason . CookieAndUATMissing ) ;
351
372
}
352
373
return undefined ;
0 commit comments