Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
chore(shared,react-router,tanstack-start): Create shared environment variable retrieval function#4985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
chore(shared,react-router,tanstack-start): Create shared environment variable retrieval function #4985
Changes from all commits
23db855f756662029dce07f808faf1ce19b9f486caa876fa72a1bd48d85c37578804b9a7cb5a9585ff10b8f584aca4aafafa68dae0cb3adb58c1fdddf3533b5152f787b44219d09261d2ea0a3ef8305f615b741784310421f6bff3db1427e01ba10271ff504File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| "@clerk/shared": minor | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the introduction of Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems fine 👍 | ||
| --- | ||
| Introduce unified environment variable handling across all supported platforms | ||
| Usage: | ||
| ```ts | ||
| import { getEnvVariable } from '@clerk/shared/getEnvVariable' | ||
| const publishableKey = getEnvVariable('CLERK_PUBLISHABLE_KEY') | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@clerk/tanstack-start': patch | ||
| '@clerk/react-router': patch | ||
| --- | ||
| Internal changes to use new `getEnvVariable` utility from `@clerk/shared` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -115,6 +115,7 @@ | ||
| "object", | ||
| "oauth", | ||
| "web3", | ||
| "getEnvVariable", | ||
| "pathMatcher" | ||
| ], | ||
| "scripts": { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| type CloudflareEnv = { env: Record<string, string> }; | ||
| const hasCloudflareProxyContext = (context: any): context is { cloudflare: CloudflareEnv } => { | ||
| return !!context?.cloudflare?.env; | ||
| }; | ||
| const hasCloudflareContext = (context: any): context is CloudflareEnv => { | ||
| return !!context?.env; | ||
| }; | ||
| /** | ||
| * Retrieves an environment variable across runtime environments. | ||
| * @param name - The environment variable name to retrieve | ||
| * @param context - Optional context object that may contain environment values | ||
| * @returns The environment variable value or empty string if not found | ||
| */ | ||
| export const getEnvVariable = (name: string, context?: Record<string, any>): string => { | ||
| // Node envs | ||
| if (typeof process !== 'undefined' && process.env && typeof process.env[name] === 'string') { | ||
| return process.env[name]; | ||
| } | ||
| // Vite specific | ||
| if (typeof import.meta !== 'undefined' && import.meta.env && typeof import.meta.env[name] === 'string') { | ||
| return import.meta.env[name]; | ||
| } | ||
| if (hasCloudflareProxyContext(context)) { | ||
| return context.cloudflare.env[name] || ''; | ||
| } | ||
| // Cloudflare | ||
| if (hasCloudflareContext(context)) { | ||
| return context.env[name] || ''; | ||
| } | ||
| // Check whether the value exists in the context object directly | ||
| if (context && typeof context[name] === 'string') { | ||
| return context[name]; | ||
| } | ||
| // Cloudflare workers | ||
| try { | ||
| return globalThis[name as keyof typeof globalThis]; | ||
| } catch { | ||
| // This will raise an error in Cloudflare Pages | ||
| } | ||
| return ''; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -24,6 +24,7 @@ export default defineConfig(overrideOptions => { | ||
| minify: false, | ||
| sourcemap: true, | ||
| dts: true, | ||
| target: 'es2020', | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To support | ||
| external: ['react', 'react-dom'], | ||
| esbuildPlugins: [WebWorkerMinifyPlugin as any], | ||
| define: { | ||
Uh oh!
There was an error while loading. Please reload this page.