Overview
Echoes of the Past uses environment variables for:- API authentication and configuration
- Database connections
- Third-party service integration
- Feature flags and runtime configuration
Required Variables
These variables are mandatory for the application to function. Missing any of these will cause runtime or build errors.Supabase (Database & Authentication)
NEXT_PUBLIC_SUPABASE_URL
Type: PublicRequired: Yes
Used in:
next.config.ts:3utils/supabase/server.ts:8utils/supabase/middleware.ts:17utils/supabase/client.ts:4
- Go to your Supabase Dashboard
- Select your project
- Navigate to Settings → API
- Copy the “Project URL”
This variable is prefixed with
NEXT_PUBLIC_ so it’s accessible in the browser. The URL in next.config.ts:12 is used to configure Next.js image optimization for Supabase Storage.NEXT_PUBLIC_SUPABASE_ANON_KEY
Type: PublicRequired: Yes
Used in:
utils/supabase/server.ts:8utils/supabase/middleware.ts:17utils/supabase/client.ts:4utils/supabase/check-env-vars.ts:4
- Go to your Supabase Dashboard
- Navigate to Settings → API
- Copy the “anon public” key
Vapi AI (Voice Conversations)
NEXT_PUBLIC_VAPI_WEB_TOKEN
Type: PublicRequired: Yes
Used in:
lib/vapi.ts:3lib/vapi.ts:7
- Sign up at Vapi AI
- Create a new application
- Navigate to API Keys
- Copy your Web Token
lib/vapi.ts:3 if this is not set:
OpenAI (AI Generation)
OPENAI_API_KEY
Type: SecretRequired: Yes
Used in:
lib/ai.ts:3lib/ai.ts:8
- Go to OpenAI Platform
- Navigate to API Keys
- Click “Create new secret key”
- Copy and store securely
lib/ai.ts:3 if not set:
ElevenLabs (Voice Synthesis)
ELEVEN_LABS_API_KEY
Type: SecretRequired: Yes
Used in:
lib/elevenlabs.ts:4
- Sign up at ElevenLabs
- Navigate to Profile → API Keys
- Generate a new API key
- Copy and store securely
ElevenLabs is used in conjunction with Vapi AI (see
features/call/hooks/useVapi.ts:47-55) to provide voice synthesis with specific voice IDs for each historical figure.Upstash Redis (Rate Limiting & Caching)
UPSTASH_REDIS_REST_URL
Type: SecretRequired: Yes
Used in:
lib/redis.ts:3lib/redis.ts:8
UPSTASH_REDIS_REST_TOKEN
Type: SecretRequired: Yes
Used in:
lib/redis.ts:3lib/redis.ts:9
- Sign up at Upstash
- Create a new Redis database
- Navigate to Details tab
- Copy “UPSTASH_REDIS_REST_URL” and “UPSTASH_REDIS_REST_TOKEN”
lib/redis.ts:3 if either is missing:
Optional Variables
These variables enhance functionality but are not strictly required for the application to run.Application Configuration
NEXT_PUBLIC_APP_URL
Type: PublicRequired: Recommended
Used in:
features/auth/components/sign-in-google-btn.tsx:21
VERCEL_URL or defaults to http://localhost:3000
Example:
features/auth/components/sign-in-google-btn.tsx:21):
NEXT_PUBLIC_SERVER_URL
Type: PublicRequired: Optional
Used in:
features/call/hooks/useVapi.ts:57
https://08ae-202-43-120-244.ngrok-free.app/api/webhook (hardcoded fallback)
When to set:
- In production for custom webhook handling
- When implementing server-side conversation logging
- For advanced Vapi AI integrations
VERCEL_URL
Type: System (Auto-set by Vercel)Required: No
Used in:
config/metadata.ts:5
config/metadata.ts:5:
You don’t need to set this manually. Vercel automatically provides it for all deployments.
NODE_ENV
Type: SystemRequired: No (Auto-set)
Used in:
app/layout.tsx:43app/(other)/auth/callback/route.ts:19
development- Local developmentproduction- Production buildstest- Test environments
app/layout.tsx:43):
app/(other)/auth/callback/route.ts:19):
Environment Setup Guide
Local Development
Production (Vercel)
Navigate to project settings
- Open your Vercel dashboard
- Select your project
- Go to Settings → Environment Variables
Add all required variables
For each variable:
- Enter the variable name
- Enter the value
- Select environments (Production, Preview, Development)
- Click “Save”
Add optional variables
Add optional variables for enhanced functionality:
NEXT_PUBLIC_APP_URL(Use your production domain)NEXT_PUBLIC_SERVER_URL(If using custom webhooks)
Security Best Practices
Do’s
- Store all secrets in Vercel’s encrypted environment variable system
- Use different API keys for development and production
- Rotate API keys regularly
- Use
NEXT_PUBLIC_prefix only for truly public variables - Set appropriate environment scopes (Production vs Preview)
- Monitor API usage and set rate limits
Don’ts
- Never commit
.envfiles to Git - Never expose server-side secrets in client components
- Don’t use production keys in development
- Don’t share API keys in screenshots or documentation
- Don’t hardcode sensitive values in source code
Checking for Exposed Secrets
Before committing, verify no secrets are exposed:.gitignore includes:
Variable Validation
The application validates critical environment variables at startup:Build-time Validation
File:next.config.ts:3-5
Runtime Validation
Multiple services validate their required variables:- Vapi:
lib/vapi.ts:3-5 - OpenAI:
lib/ai.ts:3-5 - Redis:
lib/redis.ts:3-5
Manual Validation
Check environment variable availability: File:utils/supabase/check-env-vars.ts:4
Troubleshooting
Variable Not Loaded
Problem: Environment variable returnsundefined
Solutions:
- Restart development server after adding new variables
- Verify variable name spelling (case-sensitive)
- Check if variable is in correct
.env.localfile - For
NEXT_PUBLIC_*variables, ensure they’re set at build time
Build Failures
Error: “Environment variable is not set” Solution:- Check which variable is missing from error message
- Add the variable to Vercel environment settings
- Redeploy the application
OAuth Callback Errors
Problem: Authentication redirects fail Solution:- Verify
NEXT_PUBLIC_APP_URLmatches your actual domain - Update Google OAuth callback URL to
https://yourdomain.com/auth/callback - Add callback URL to Supabase redirect allowlist
API Rate Limiting
Problem: Too many API requests Solution:- Verify Redis is properly configured
- Check
UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKEN - Monitor Redis usage in Upstash dashboard
Quick Reference
Minimum Required Variables
Production Variables
Add these for production:Variable Prefix Guide
NEXT_PUBLIC_*- Exposed to browser, safe for client-side code- No prefix - Server-side only, never exposed to client
VERCEL_*- Automatically set by Vercel platformNODE_ENV- Automatically set by runtime environment