Environment Variables

Configure your went application with environment variables for different environments.

Required Variables

Database Configuration
DATABASE_URL=postgresql://username:password@localhost:5432/database

PostgreSQL connection string for your database. Used by Prisma for database operations.

DIRECT_URL=postgresql://username:password@localhost:5432/database

Direct database connection URL. Required for some hosting providers like Supabase.

Authentication
AUTH_SECRET=your-32-character-secret-key

Secret key for NextAuth.js session encryption. Generate with openssl rand -base64 32

NEXTAUTH_URL=http://localhost:3000

Base URL of your application. Used for callback URLs and redirects.

Optional Variables

Email Service (Resend)
RESEND_API_KEY=re_123456789

Resend API key for sending emails (password reset, welcome emails).

Note: Without this variable, email functionality will be disabled but the app will still work.

Google OAuth (Optional)
GOOGLE_CLIENT_ID=your-google-client-id

Google OAuth client ID from Google Cloud Console.

GOOGLE_CLIENT_SECRET=your-google-client-secret

Google OAuth client secret from Google Cloud Console.

Tip: When both Google OAuth variables are set, Google sign-in buttons automatically appear.

Payment Processing (Stripe)
STRIPE_SECRET_KEY=sk_test_or_live_key

Stripe secret key for processing payments.

NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_or_live_key

Stripe publishable key for client-side Stripe integration.

STRIPE_WEBHOOK_SECRET=whsec_webhook_secret

Stripe webhook endpoint secret for verifying webhook signatures.

Environment Setup

.env File Structure
# Database
DATABASE_URL="postgresql://user:password@localhost:5432/went_db"
DIRECT_URL="postgresql://user:password@localhost:5432/went_db"

# Authentication
AUTH_SECRET="your-32-character-secret-key-here"
NEXTAUTH_URL="http://localhost:3000"

# Email (Optional)
RESEND_API_KEY="re_your_resend_api_key"

# Google OAuth (Optional)
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"

# Stripe (Optional)
STRIPE_SECRET_KEY="sk_test_your_stripe_secret_key"
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_your_stripe_publishable_key"
STRIPE_WEBHOOK_SECRET="whsec_your_webhook_secret"
Different Environments

Development

Use local database and test API keys:

DATABASE_URL="postgresql://localhost:5432/went_dev"
NEXTAUTH_URL="http://localhost:3000"

Production

Use production database and live API keys:

DATABASE_URL="postgresql://prod-server:5432/went_prod"
NEXTAUTH_URL="https://yourdomain.com"

Security Best Practices

Never Commit Secrets

  • • Add .env to your .gitignore file
  • • Use .env.example for documenting required variables
  • • Never hardcode secrets in your source code
  • • Use different secrets for different environments

Deployment Considerations

  • • Use your hosting platform's environment variable settings
  • • Rotate secrets regularly in production
  • • Use strong, randomly generated secrets
  • • Validate required environment variables on startup

Development Tips

  • • Copy .env.example to .env to get started
  • • Use tools like dotenv-cli for environment switching
  • • Document new environment variables in .env.example
  • • Test with different environment configurations

Quick Setup

Getting Started Commands

1. Copy the example environment file:

cp .env.example .env

2. Generate a secure AUTH_SECRET:

openssl rand -base64 32

3. Update your database connection string and run migrations:

went db migrate init

Next Steps

Continue your journey with Went: