diff --git a/packages/chrome-extension/src/internal/clerk.ts b/packages/chrome-extension/src/internal/clerk.ts index beffba8a27..ec63e6ed8b 100644 --- a/packages/chrome-extension/src/internal/clerk.ts +++ b/packages/chrome-extension/src/internal/clerk.ts @@ -34,6 +34,8 @@ export async function createClerkClient({ syncHost = process.env.CLERK_SYNC_HOST, syncSessionWithTab = false, }: CreateClerkClientOptions): Promise { + console.log('createClerkClient (props):', { publishableKey, scope, storageCache, syncHost, syncSessionWithTab }); + if (clerk) { return clerk; } @@ -52,12 +54,16 @@ export async function createClerkClient({ }); // Set up JWT handler and attempt to get JWT from storage on initialization - const jwt = JWTHandler(storageCache, { + + const jwtOptions = { frontendApi: key.frontendApi, name: isProd ? CLIENT_JWT_KEY : DEV_BROWSER_JWT_KEY, sync: syncSessionWithTab, url: syncHost || isProd ? `https://${key.frontendApi}` : DEFAULT_LOCAL_HOST_PERMISSION, - }); + }; + + console.log('JWTHandler (options):', jwtOptions); + const jwt = JWTHandler(storageCache, jwtOptions); // Create Clerk instance clerk = new Clerk(publishableKey); diff --git a/packages/chrome-extension/src/internal/utils/jwt-handler.ts b/packages/chrome-extension/src/internal/utils/jwt-handler.ts index 9fbe13d884..f211f2bc7a 100644 --- a/packages/chrome-extension/src/internal/utils/jwt-handler.ts +++ b/packages/chrome-extension/src/internal/utils/jwt-handler.ts @@ -29,6 +29,7 @@ export function JWTHandler(store: StorageCache, params: JWTHandlerParams) { * @param value: JWT generally from the cookie or authorization header */ const set = async (value: string): Promise => { + console.log('JWTHandler.set:', CACHE_KEY, value); return await store.set(CACHE_KEY, value).catch(errorLogger); }; @@ -36,6 +37,7 @@ export function JWTHandler(store: StorageCache, params: JWTHandlerParams) { * Remove the JWT value */ const remove = async (): Promise => { + console.log('JWTHandler.remove:', CACHE_KEY); return await store.remove(CACHE_KEY).catch(errorLogger); }; @@ -44,10 +46,15 @@ export function JWTHandler(store: StorageCache, params: JWTHandlerParams) { * If not set, attempt to get it from the synced session and save for later use. */ const get = async () => { + console.log('JWTHandler.get:', CACHE_KEY); + console.log('JWTHandler.get (shouldSync):', shouldSync(sync, cookieParams)); + if (shouldSync(sync, cookieParams)) { + console.dir({ cookieParams, sync, shouldSync: true }); // Get client cookie from browser const syncedJWT = await getClientCookie(cookieParams).catch(errorLogger); + console.log('JWTHandler.get (syncedJWT):', syncedJWT); if (syncedJWT) { // Set client cookie in StorageCache await set(syncedJWT.value); @@ -55,8 +62,11 @@ export function JWTHandler(store: StorageCache, params: JWTHandlerParams) { } } + const value = await store.get(CACHE_KEY); + console.log('JWTHandler.get (value):', value); + // Get current JWT from StorageCache - return await store.get(CACHE_KEY); + return value; }; /** diff --git a/packages/chrome-extension/src/internal/utils/request-handler.ts b/packages/chrome-extension/src/internal/utils/request-handler.ts index 11bb0417ae..27afc60357 100644 --- a/packages/chrome-extension/src/internal/utils/request-handler.ts +++ b/packages/chrome-extension/src/internal/utils/request-handler.ts @@ -19,6 +19,9 @@ export function requestHandler(jwtHandler: JWTHandler) { requestInit.url?.searchParams.append('_is_native', '1'); (requestInit.headers as Headers).set(AUTH_HEADER, `Bearer ${currentJWT}`); + + console.log('requestHandler (searchParams):', requestInit.url?.searchParams.toString()); + console.log('requestHandler (authHeader):', AUTH_HEADER, `Bearer ${currentJWT}`); }; return handler; diff --git a/packages/chrome-extension/src/internal/utils/response-handler.ts b/packages/chrome-extension/src/internal/utils/response-handler.ts index 73ba8e1dde..ac9654947a 100644 --- a/packages/chrome-extension/src/internal/utils/response-handler.ts +++ b/packages/chrome-extension/src/internal/utils/response-handler.ts @@ -10,6 +10,8 @@ export function responseHandler(jwtHandler: JWTHandler) { const handler: Handler = async (_, response) => { const authHeader = response?.headers.get(AUTH_HEADER); + console.log('responseHandler (authHeader):', authHeader); + if (authHeader?.startsWith('Bearer')) { const newJWT = authHeader.split(' ')[1] || undefined;