Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Environment Variables Template
# Copy this file to .env and fill in your values

# Clerk Authentication
PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_example_key_here

# Convex Database
PUBLIC_CONVEX_URL=https://example.convex.cloud
PUBLIC_CLERK_PUBLISHABLE_KEY=pk_something
CONVEX_DEPLOYMENT=dev:something
PUBLIC_CONVEX_URL=https://something.convex.cloud
5 changes: 2 additions & 3 deletions src/lib/components/providers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
import { ClerkProvider, GoogleOneTap } from 'svelte-clerk/client';
import { ModeWatcher } from 'mode-watcher';
import { setupConvex } from 'convex-svelte';
import { PUBLIC_CLERK_PUBLISHABLE_KEY, PUBLIC_CONVEX_URL } from '$env/static/public';

// Props
let { children } = $props();

// Setup Convex
setupConvex(PUBLIC_CONVEX_URL);
setupConvex(process.env.PUBLIC_CONVEX_URL || '');
</script>

<ClerkProvider publishableKey={PUBLIC_CLERK_PUBLISHABLE_KEY}>
<ClerkProvider publishableKey={process.env.PUBLIC_CLERK_PUBLISHABLE_KEY || ''}>
<GoogleOneTap />
<ModeWatcher disableTransitions={false} defaultMode={'dark'} />
{@render children()}
Expand Down
14 changes: 11 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
plugins: [tailwindcss(), sveltekit()]
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');

return {
plugins: [tailwindcss(), sveltekit()],
define: {
'process.env.PUBLIC_CONVEX_URL': JSON.stringify(env.PUBLIC_CONVEX_URL),
'process.env.PUBLIC_CLERK_PUBLISHABLE_KEY': JSON.stringify(env.PUBLIC_CLERK_PUBLISHABLE_KEY)
}
Comment on lines +10 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for missing environment variables.

The current implementation doesn't handle cases where required environment variables are missing. Consider adding validation or warnings.

 	return {
 		plugins: [tailwindcss(), sveltekit()],
+		define: {
+			'process.env.PUBLIC_CONVEX_URL': JSON.stringify(env.PUBLIC_CONVEX_URL || ''),
+			'process.env.PUBLIC_CLERK_PUBLISHABLE_KEY': JSON.stringify(env.PUBLIC_CLERK_PUBLISHABLE_KEY || '')
+		}
-		define: {
-			'process.env.PUBLIC_CONVEX_URL': JSON.stringify(env.PUBLIC_CONVEX_URL),
-			'process.env.PUBLIC_CLERK_PUBLISHABLE_KEY': JSON.stringify(env.PUBLIC_CLERK_PUBLISHABLE_KEY)
-		}
 	};

Or add validation:

const requiredEnvVars = ['PUBLIC_CONVEX_URL', 'PUBLIC_CLERK_PUBLISHABLE_KEY'];
const missingVars = requiredEnvVars.filter(key => !env[key]);
if (missingVars.length > 0) {
	console.warn(`Missing environment variables: ${missingVars.join(', ')}`);
}
🤖 Prompt for AI Agents
In vite.config.ts around lines 10 to 13, the environment variables
PUBLIC_CONVEX_URL and PUBLIC_CLERK_PUBLISHABLE_KEY are used without checking if
they are defined. Add validation before this block to check if these variables
exist in env, and if any are missing, log a warning listing the missing
variables. This will help catch configuration issues early.

};
});