@@ -3,6 +3,7 @@ import { constants } from '@clerk/backend';
33import cookie from 'cookie' ;
44import type { IncomingMessage , ServerResponse } from 'http' ;
55
6+ import { loadApiEnv , loadClientEnv } from './clerkClient' ;
67import { handleValueOrFn , isHttpOrHttps , isProxyUrlRelative , isValidProxyUrl } from './shared' ;
78import type { ClerkMiddlewareOptions } from './types' ;
89
@@ -46,16 +47,16 @@ export const authenticateRequest = (opts: {
4647 options ?: ClerkMiddlewareOptions ;
4748} ) => {
4849 const { clerkClient, apiKey, secretKey, frontendApi, publishableKey, req, options } = opts ;
49- const cookies = parseCookies ( req ) ;
5050 const { jwtKey, authorizedParties, audience } = options || { } ;
5151
52+ const env = { ...loadApiEnv ( ) , ...loadClientEnv ( ) } ;
53+
5254 const requestUrl = getRequestUrl ( req ) ;
53- const isSatellite =
54- handleValueOrFn ( options ?. isSatellite , requestUrl ) || process . env . CLERK_IS_SATELLITE === 'true' || false ;
55- const domain = handleValueOrFn ( options ?. domain , requestUrl ) || process . env . CLERK_DOMAIN || '' ;
56- const signInUrl = options ?. signInUrl || process . env . CLERK_SIGN_IN_URL || '' ;
55+ const isSatellite = handleValueOrFn ( options ?. isSatellite , requestUrl , env . isSatellite ) ;
56+ const domain = handleValueOrFn ( options ?. domain , requestUrl ) || env . domain ;
57+ const signInUrl = options ?. signInUrl || env . signInUrl ;
5758 const proxyUrl = absoluteProxyUrl (
58- handleValueOrFn ( options ?. proxyUrl , requestUrl , process . env . CLERK_PROXY_URL ) as string ,
59+ handleValueOrFn ( options ?. proxyUrl , requestUrl , env . proxyUrl ) ,
5960 requestUrl . toString ( ) ,
6061 ) ;
6162
@@ -67,6 +68,8 @@ export const authenticateRequest = (opts: {
6768 throw new Error ( satelliteAndMissingSignInUrl ) ;
6869 }
6970
71+ const cookies = parseCookies ( req ) ;
72+
7073 return clerkClient . authenticateRequest ( {
7174 audience,
7275 apiKey,
0 commit comments