Environment Variables

Complete list of all environment variables used by the application.

Quick Reference

bash
cp .env.example .env

Copy to .env and fill in values

Required Variables

These must be set for the app to function:

Database

VariableDescriptionExample
DATABASE_URLPostgreSQL connection stringpostgresql://user:pass@host:5432/db

Used in: /prisma/schema.prisma

How to get DATABASE_URL:

ProviderInstructions
SupabaseGo to Supabase Project → Connect → ORMs → Prisma and copy the DIRECT_URL
NeonGo to your Neon project → Dashboard → Connect to your database, and copy the Connection string

Authentication

VariableDescriptionExample
AUTH_SECRETNextAuth.js secret (32+ chars)your-super-secret-key-here-32-chars
NEXTAUTH_URLApp URL for auth callbackshttp://localhost:3000
GOOGLE_CLIENT_IDGoogle OAuth client ID123456789.apps.googleusercontent.com
GOOGLE_CLIENT_SECRETGoogle OAuth client secretGOCSPX-xxxxxxxxxxxxx

Used in: /lib/auth.ts, /api/auth/, /api/send-welcome-email/

Payments

VariableDescriptionExample
PAYMENT_PROVIDERActive payment providerstripe or razorpay

Default: stripe if not set.

Stripe

VariableDescriptionExample
STRIPE_SECRET_KEYStripe API secret keysk_test_xxxxxxxxxxxxx
STRIPE_PUBLISHABLE_KEYStripe publishable keypk_test_xxxxxxxxxxxxx
STRIPE_WEBHOOK_SECRETWebhook endpoint secretwhsec_xxxxxxxxxxxxx

Used in: /lib/payments/stripe.ts, /api/payments/

Razorpay (Alternative to Stripe)

VariableDescriptionExample
RAZORPAY_KEY_IDRazorpay API key IDrzp_test_xxxxxxxxxxxx
RAZORPAY_KEY_SECRETRazorpay API key secretxxxxxxxxxxxxxxxx
RAZORPAY_WEBHOOK_SECRETWebhook endpoint secret (you generate this yourself)[generated hex string]

Used in: /lib/payments/razorpay.ts, /api/payments/

Important: Unlike Stripe, Razorpay requires you to generate your own webhook secret. You generate a random secret, use it when creating the webhook in Razorpay dashboard, and add the same secret to your .env file. See Payment Setup for detailed generation instructions.

Email

VariableDescriptionExample
RESEND_API_KEYResend API keyre_xxxxxxxxxxxxx
EMAIL_FROMSender email addressnoreply@yourdomain.com

Used in: /lib/email.ts, /api/auth/magic-link/

App Details

VariableDescriptionExample
NEXT_PUBLIC_APP_URLPublic app URL (for SEO/sitemap)https://yourdomain.com
NEXT_PUBLIC_APP_NAMEApp name for branding"Your SaaS"

Used in: /lib/seo.ts, /app/sitemap.ts, /app/robots.ts, /components/

Getting API Keys

AUTH_SECRET

Generate a random string:

bash
openssl rand -base64 32

Or use: generate-secret.vercel.app

Google OAuth

  1. Go to Google Cloud Console
  2. Create a project or select existing
  3. Go to APIs & Services → Credentials
  4. Create OAuth 2.0 Client ID
  5. Add authorized redirect URIs:
    • Development: http://localhost:3000/api/auth/callback/google
    • Production: https://yourdomain.com/api/auth/callback/google
  6. Copy Client ID and Client Secret

Payment Provider Keys

For Stripe and Razorpay API keys, webhook setup, and detailed configuration instructions, see Payment Setup.

Resend API Key

  1. Go to Resend Dashboard
  2. API Keys → Create API Key
  3. Copy the key

Database URL

Format: postgresql://USER:PASSWORD@HOST:PORT/DATABASE

Local PostgreSQL:

bash
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/saas"

Supabase:

bash
DATABASE_URL="postgresql://postgres:[password]@db.[project].supabase.co:5432/postgres"

Neon:

bash
DATABASE_URL="postgresql://[user]:[password]@[endpoint].neon.tech/[database]?sslmode=require"

Optional Variables

These have defaults or fallbacks:

VariableDescriptionDefault
SUPPORT_EMAILContact form recipientFalls back to EMAIL_FROM

Error Tracking (Optional)

VariableDescriptionExample
SENTRY_DSNSentry server-side DSNhttps://xxx@sentry.io/xxx
SENTRY_ENVIRONMENTEnvironment namedevelopment or production
NEXT_PUBLIC_SENTRY_DSNSentry client-side DSNhttps://xxx@sentry.io/xxx

Note: Sentry is optional. If not configured, the app works normally without error tracking.

Used in: sentry.*.config.ts, error boundaries, API routes

AI Providers (Optional)

VariableDescriptionExample
OPENAI_API_KEYOpenAI API secret keysk-xxxxxxxxxxxxxxxx
ANTHROPIC_API_KEYAnthropic API secret keysk-ant-xxxxxxxxxxxxx
GEMINI_API_KEYGoogle Gemini API keyAIzaSyxxxxxxxxxxxxxxxxxxxxx

Note: AI providers are optional. The app works normally without them. Configure at least one provider to enable AI features.

Used in: /lib/ai/providers/

Environment File Template

Create .env file with these values:

bash
# ===================
# APP DETAILS
# ===================
NEXT_PUBLIC_APP_URL=http://localhost:3000
NEXT_PUBLIC_APP_NAME="Your SaaS"

# ===================
# DATABASE
# ===================
DATABASE_URL="postgresql://username:password@localhost:5432/saas_db"

# ===================
# AUTHENTICATION
# ===================
AUTH_SECRET=generate-a-random-32-character-string-here
NEXTAUTH_URL=http://localhost:3000

# Google OAuth (from Google Cloud Console)
GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-google-client-secret

# ===================
# PAYMENTS
# ===================
# Select payment provider: "stripe" (default) or "razorpay"
PAYMENT_PROVIDER=stripe

# --- Stripe (if using Stripe) ---
STRIPE_SECRET_KEY=sk_test_your-stripe-secret-key
STRIPE_PUBLISHABLE_KEY=pk_test_your-stripe-publishable-key
STRIPE_WEBHOOK_SECRET=whsec_your-webhook-secret

# --- Razorpay (if using Razorpay) ---
# RAZORPAY_KEY_ID=rzp_test_your-razorpay-key-id
# RAZORPAY_KEY_SECRET=your-razorpay-key-secret
# RAZORPAY_WEBHOOK_SECRET=your-razorpay-webhook-secret

# ===================
# EMAIL (Resend)
# ===================
RESEND_API_KEY=re_your-resend-api-key
EMAIL_FROM=noreply@yourdomain.com
SUPPORT_EMAIL=noreply@yourdomain.com

# ===================
# AI PROVIDERS (Optional)
# ===================
# OpenAI (for GPT models)
OPENAI_API_KEY=sk-your-openai-api-key

# Anthropic (for Claude models)
ANTHROPIC_API_KEY=sk-ant-your-anthropic-api-key

# Google Gemini
GEMINI_API_KEY=AIzaSy-your-gemini-api-key

# ===================
# ERROR TRACKING (Optional - Sentry)
# ===================
SENTRY_ENVIRONMENT=development

# Server-side error tracking
SENTRY_DSN=https://1234567890abcdef1234567890abcdef@o123456.ingest.sentry.io/1234567

# Client-side error tracking
NEXT_PUBLIC_SENTRY_DSN=https://1234567890abcdef1234567890abcdef@o123456.ingest.sentry.io/1234567

Development vs Production

Development (.env)

bash
NEXT_PUBLIC_APP_URL=http://localhost:3000
NEXTAUTH_URL=http://localhost:3000
STRIPE_SECRET_KEY=sk_test_...
STRIPE_PUBLISHABLE_KEY=pk_test_...

Production (Vercel Dashboard)

bash
NEXT_PUBLIC_APP_URL=https://yourdomain.com
NEXTAUTH_URL=https://yourdomain.com
STRIPE_SECRET_KEY=sk_live_...
STRIPE_PUBLISHABLE_KEY=pk_live_...

Vercel Environment Variables

In Vercel Dashboard → Project → Settings → Environment Variables:

  1. Add each variable
  2. Select environments (Production, Preview, Development)
  3. Some variables need specific scopes:
    • NEXT_PUBLIC_* - Exposed to browser
    • Others - Server-side only

Validation

The app validates required variables at startup:

  • Missing STRIPE_SECRET_KEY → Error on startup
  • Missing STRIPE_WEBHOOK_SECRET → Error on startup
  • Missing RESEND_API_KEY → Error on startup
  • Missing DATABASE_URL → Prisma connection fails

Troubleshooting

"STRIPE_SECRET_KEY is required"

Add Stripe keys to .env:

bash
STRIPE_SECRET_KEY=sk_test_xxxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxxx

"RESEND_API_KEY is required"

Add Resend key to .env:

bash
RESEND_API_KEY=re_xxxxx

"Invalid `prisma.user.findUnique()` invocation"

Check DATABASE_URL is valid and database is running.

"Google OAuth redirect_uri mismatch"

Verify redirect URI in Google Console matches exactly:

  • http://localhost:3000/api/auth/callback/google (dev)
  • https://yourdomain.com/api/auth/callback/google (prod)