Open History to see the last commit
1export function clerkFrontendApiUrlFromPublishableKey(publishableKey: string): string {
2 const encodedFrontendApi = publishableKey.split("_").slice(2).join("_");
3 const frontendApi = globalThis.atob(encodedFrontendApi).replace(/\$$/u, "");
4 if (frontendApi.length === 0 || frontendApi.includes("/")) {
5 throw new Error("Invalid Clerk publishable key.");
6 }
7 return `https://${frontendApi}`;
8}
9
10export function clerkFrontendApiHostnameFromPublishableKey(publishableKey: string): string {
11 return new URL(clerkFrontendApiUrlFromPublishableKey(publishableKey)).hostname;
12}
13
14export function isAllowedClerkFrontendApiHostname(
15 hostname: string,
16 configuredHostname: string | null,
17): boolean {
18 return (
19 hostname.endsWith(".clerk.accounts.dev") ||
20 hostname.endsWith(".clerk.accounts.com") ||
21 hostname === configuredHostname
22 );
23}
24
25export function relayClerkTokenOptions(template: string) {
26 return {
27 template,
28 skipCache: true,
29 } as const;
30}