@@ -5,10 +5,9 @@ import browser from 'webextension-polyfill';
55
66import { SCOPE , type Scope } from '../types' ;
77import { AUTH_HEADER , CLIENT_JWT_KEY , DEFAULT_LOCAL_HOST_PERMISSION } from './constants' ;
8- import type { GetClientCookieParams } from './utils/cookies' ;
98import { assertPublishableKey } from './utils/errors' ;
109import { JWTHandler } from './utils/jwt-handler' ;
11- import { getValidPossibleManifestHosts , validateHostPermissionExistence , validateManifest } from './utils/manifest' ;
10+ import { validateManifest } from './utils/manifest' ;
1211import { BrowserStorageCache , type StorageCache } from './utils/storage' ;
1312
1413export let clerk : Clerk ;
@@ -22,13 +21,15 @@ export type CreateClerkClientOptions = {
2221 publishableKey : string ;
2322 scope ?: Scope ;
2423 storageCache ?: StorageCache ;
24+ syncHost ?: string ;
2525 syncSessionWithTab ?: boolean ;
2626} ;
2727
2828export async function createClerkClient ( {
2929 publishableKey,
3030 scope,
3131 storageCache = BrowserStorageCache ,
32+ syncHost = process . env . CLERK_SYNC_HOST ,
3233 syncSessionWithTab = false ,
3334} : CreateClerkClientOptions ) : Promise < Clerk > {
3435 if ( clerk ) {
@@ -37,46 +38,26 @@ export async function createClerkClient({
3738
3839 // Parse publishableKey and assert it's present/valid, throw if not
3940 const key = parsePublishableKey ( publishableKey ) ;
41+
42+ console . log ( 'KEY' , key , key ?. instanceType , key ?. frontendApi ) ;
4043 assertPublishableKey ( key ) ;
4144
4245 const isProd = key . instanceType === 'production' ;
4346 const manifest = browser . runtime . getManifest ( ) ;
4447
4548 // Will throw if manifest is invalid
4649 validateManifest ( manifest , {
47- sync : syncSessionWithTab ,
4850 background : scope === SCOPE . background ,
51+ sync : syncSessionWithTab ,
4952 } ) ;
5053
51- let jwt : JWTHandler | undefined ;
52-
53- if ( syncSessionWithTab ) {
54- const hostHint = isProd ? key . frontendApi : DEFAULT_LOCAL_HOST_PERMISSION ;
55- const validHosts = getValidPossibleManifestHosts ( manifest ) ;
56-
57- // Will throw if manifest host_permissions doesn't contain a valid host
58- validateHostPermissionExistence ( validHosts , hostHint ) ;
59-
60- // Set up cookie params based on environment
61- const getClientCookieParams : GetClientCookieParams = isProd
62- ? {
63- urls : `https://${ key . frontendApi } ` ,
64- name : CLIENT_JWT_KEY ,
65- }
66- : {
67- urls : validHosts ,
68- name : DEV_BROWSER_JWT_KEY ,
69- } ;
70-
71- // Set up JWT handler and attempt to get JWT from storage on initialization
72- jwt = JWTHandler ( storageCache , { ...getClientCookieParams , frontendApi : key . frontendApi , sync : true } ) ;
73- } else {
74- jwt = JWTHandler ( storageCache , { frontendApi : key . frontendApi , sync : false } ) ;
75- }
76-
77- if ( ! jwt ) {
78- throw new Error ( 'StorageCache could not be initialized.' ) ; // TODO: Update error
79- }
54+ // Set up JWT handler and attempt to get JWT from storage on initialization
55+ const jwt = JWTHandler ( storageCache , {
56+ frontendApi : key . frontendApi ,
57+ name : isProd ? CLIENT_JWT_KEY : DEV_BROWSER_JWT_KEY ,
58+ sync : syncSessionWithTab ,
59+ url : syncHost || isProd ? `https://${ key . frontendApi } ` : DEFAULT_LOCAL_HOST_PERMISSION ,
60+ } ) ;
8061
8162 // Create Clerk instance
8263 clerk = new Clerk ( publishableKey ) ;
0 commit comments