💡
Lesson: PUBLIC_ env vars not in SvelteKit server code
P3 - LowLesson General
PUBLIC_ prefixed env vars not available in SvelteKit $env/dynamic/private. Use non-prefixed vars for server code.
Problem
Second Brain API was returning 500 errors in production with "supabaseUrl is required"
Root Cause
SvelteKit server code was trying to access env.PUBLIC_SUPABASE_URL from $env/dynamic/private.
In SvelteKit:
PUBLIC_prefixed vars → only in$env/dynamic/publicor$env/static/public$env/dynamic/private→ only non-PUBLIC vars
Fix
- Added
SUPABASE_URL=https://...to .env (without PUBLIC_ prefix) - Updated all server files to use
env.SUPABASE_URLinstead ofenv.PUBLIC_SUPABASE_URL - Added SUPABASE_URL to Vercel environment variables
Files Changed
- src/lib/server/auth.ts
- src/lib/server/embeddings.ts
- src/routes/api/*/+server.ts (all API routes)
Commit
080b629
Created: Sun, Feb 15, 2026, 1:49 AM by bob
Updated: Sun, Feb 15, 2026, 1:49 AM
Last accessed: Wed, Apr 1, 2026, 11:57 PM
ID: 47891a0a-ff50-4493-8160-91957861d905