Environment Variables
Goal
Understand all required and optional environment variables, what breaks if they're missing, and how to set up local development.
Quick Start
- Copy
.env.exampleto.env.local - Fill in required variables
- Start dev server:
npm run dev
Required for production:
- Supabase credentials
- AWS S3 credentials
- Redis (Upstash for production)
Required Environment Variables
Supabase (Database)
Required for: All database operations, authentication
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-keyWhat breaks if missing:
- ❌ Authentication fails
- ❌ Database queries fail
- ❌ Deck creation fails
- ❌ User sessions don't work
Get from: Supabase Dashboard
AWS S3 (Storage)
Required for: PDF storage, image uploads, file hosting
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
AWS_REGION=us-east-2
S3_BUCKET=your-bucket-nameWhat breaks if missing:
- ❌ PDF uploads fail
- ❌ Image uploads fail
- ❌ File storage doesn't work
- ❌ Deck PDFs can't be served
Get from: AWS Console → IAM → Access Keys
Redis (Caching & Rate Limiting)
Required for: Rate limiting, caching, session management
Local development:
REDIS_URL=redis://localhost:6379Production (Upstash):
UPSTASH_REDIS_REST_URL=https://your-redis.upstash.io
UPSTASH_REDIS_REST_TOKEN=your-upstash-tokenWhat breaks if missing:
- ⚠️ Rate limiting disabled (security risk in production)
- ⚠️ Caching doesn't work (slower performance)
- ✅ App still works, but less secure/performant
Get from: Upstash Console
Optional but Recommended
Email Service (Resend)
Required for: Email notifications, onboarding emails
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxxx
RESEND_FROM_EMAIL=Coachable Cards <noreply@c.cards>
RESEND_FROM_EMAIL_ONBOARDING=Coachable Cards <onboarding@c.cards>
RESEND_REPLY_TO=support@coachablecards.comWhat breaks if missing:
- ⚠️ Email notifications don't send
- ⚠️ Onboarding emails fail
- ✅ App still works, but no emails
Get from: Resend API Keys
Analytics (PostHog)
Required for: User analytics, event tracking
NEXT_PUBLIC_POSTHOG_KEY=phc_xxxxx
NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.comWhat breaks if missing:
- ⚠️ Analytics don't track
- ⚠️ User events not recorded
- ✅ App still works, but no analytics
Get from: PostHog Project Settings
Payment Processing (Stripe)
Required for: Payments, subscriptions
STRIPE_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxx
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_xxxxxxxxxxxxxxxxxxxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxx
STRIPE_WEBHOOK_SECRET_CREATE=whsec_xxxxxxxxxxxxxxxxxxxxxWhat breaks if missing:
- ⚠️ Payment processing fails
- ⚠️ Subscriptions don't work
- ✅ App still works, but no payments
Get from: Stripe Dashboard
AI Services (OpenAI)
Required for: AI features, card generation
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxWhat breaks if missing:
- ⚠️ AI card generation fails
- ⚠️ AI features don't work
- ✅ App still works, but no AI features
Get from: OpenAI Platform
Local Development Quick Start
1. Copy Environment Template
cp env.example .env.local2. Fill in Required Variables
Minimum for local dev:
# Supabase (required)
NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321 # Local Supabase
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-local-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-local-service-key
# Redis (optional for local)
REDIS_URL=redis://localhost:6379
# Base URL
NEXT_PUBLIC_BASE_URL=http://localhost:3000
NEXT_PUBLIC_SITE_URL=http://localhost:30003. Start Local Supabase (Optional)
npx supabase startThis will give you local Supabase credentials.
4. Start Local Redis (Optional)
# Using Docker
docker run -d -p 6379:6379 redis
# Or using Homebrew
brew install redis
brew services start redis5. Start Development Server
npm install
npm run devVisit http://localhost:3000
Environment Validation
The app validates environment variables on startup. Check the console for:
- ✅ Required vars present → App works
- ⚠️ Optional vars missing → App works with limited features
- ❌ Required vars missing → App fails to start
Validation Function
// lib/env-validation.ts
validateEnv() // Returns validation resultsProduction Checklist
Before deploying to production, ensure:
- [ ] All required variables set in Vercel/environment
- [ ]
NODE_ENV=production - [ ] Upstash Redis configured (not local Redis)
- [ ] Production Supabase project configured
- [ ] Production S3 bucket configured
- [ ] PostHog configured (for analytics)
- [ ] Resend configured (for emails)
- [ ] Stripe configured (if using payments)
- [ ]
NEXT_PUBLIC_BASE_URLset to production domain - [ ]
NEXT_PUBLIC_SITE_URLset to production domain
Common Issues
Issue: "Missing required environment variable"
Symptom: App fails to start, error in console
Cause: Required variable not set
Fix:
- Check
.env.localexists - Verify variable name is correct
- Restart dev server:
npm run dev
Issue: "Rate limiting not working"
Symptom: No rate limits applied
Cause: Redis/Upstash not configured
Fix:
- Local: Set
REDIS_URL=redis://localhost:6379 - Production: Set
UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKEN
Issue: "PostHog not firing"
Symptom: Analytics events not tracked
Cause: PostHog keys not set
Fix: Set NEXT_PUBLIC_POSTHOG_KEY and NEXT_PUBLIC_POSTHOG_HOST
See Troubleshooting Guide for more.
Next Steps
- Troubleshooting - Fix environment issues
- URL Patterns - Understand routing
- First Deck Guide - Create your first deck
Environment issues? → Troubleshooting Guide