-
Notifications
You must be signed in to change notification settings - Fork 331
/
Copy pathClerkProvider.tsx
46 lines (39 loc) · 1.42 KB
/
ClerkProvider.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { Clerk } from '@clerk/clerk-js/no-rhc';
import type { ClerkProviderProps as ClerkReactProviderProps } from '@clerk/clerk-react';
import { ClerkProvider as ClerkReactProvider } from '@clerk/clerk-react';
import React from 'react';
import { createClerkClient } from '../internal/clerk';
import type { StorageCache } from '../internal/utils/storage';
type ChromeExtensionClerkProviderProps = ClerkReactProviderProps & {
/**
* @experimental
* @description Enables the listener to sync host cookies on changes.
*/
__experimental_syncHostListener?: boolean;
storageCache?: StorageCache;
syncHost?: string;
};
export function ClerkProvider(props: ChromeExtensionClerkProviderProps): JSX.Element | null {
const { children, storageCache, syncHost, __experimental_syncHostListener, ...rest } = props;
const { publishableKey = '' } = props;
const [clerkInstance, setClerkInstance] = React.useState<Clerk | null>(null);
React.useEffect(() => {
void (async () => {
setClerkInstance(
await createClerkClient({ publishableKey, storageCache, syncHost, __experimental_syncHostListener }),
);
})();
}, [publishableKey, storageCache, syncHost, __experimental_syncHostListener]);
if (!clerkInstance) {
return null;
}
return (
<ClerkReactProvider
{...rest}
Clerk={clerkInstance}
standardBrowser={!syncHost}
>
{children}
</ClerkReactProvider>
);
}