UNPKG

svelte-clerk

Version:

Svelte Clerk is the easiest way to add authentication and user management to your Svelte and SvelteKit applications. Add sign up, sign in, and profile management to your application in minutes.

34 lines (33 loc) 1.18 kB
import { createClerkClient } from '@clerk/backend'; import { API_URL, API_VERSION, TELEMETRY_DEBUG, TELEMETRY_DISABLED } from './constants.js'; import { getDynamicPrivateEnvVariables } from '../utils/getDynamicPrivateEnvVariables'; let clerkClientSingleton; function getClerkClient() { if (clerkClientSingleton) { return clerkClientSingleton; } const { secretKey, jwtKey } = getDynamicPrivateEnvVariables(); const client = createClerkClient({ secretKey, apiUrl: API_URL, apiVersion: API_VERSION, jwtKey, telemetry: { disabled: TELEMETRY_DISABLED, debug: TELEMETRY_DEBUG } }); // Don't memoize until the secret key is readable, so an access that happens // before dynamic env is populated doesn't permanently capture a keyless client. if (secretKey) { clerkClientSingleton = client; } return client; } export const clerkClient = new Proxy({}, { get(_target, prop) { const client = getClerkClient(); const value = Reflect.get(client, prop, client); return typeof value === 'function' ? value.bind(client) : value; } });