Skip to main content

Environment Variables

Complete reference guide for all environment variables used in the WhatsApp WAHA Dashboard.
Never commit .env files to version control. Use .env.example as a template and keep your actual credentials secure.

Quick Start

Copy the example environment file:
Then fill in your actual values.

Required Variables

Database Configuration

string
required
MongoDB connection string for storing application data.Format: mongodb+srv://username:password@cluster.mongodb.net/database-nameExample:
Notes:
  • Use MongoDB Atlas for hosted database
  • Ensure network access is configured (0.0.0.0/0 for Vercel)
  • Database is automatically created if it doesn’t exist
  • Prisma will manage schema migrations

WhatsApp API Configuration

string
required
Base URL for your WAHA (WhatsApp HTTP API) server.Example:
Notes:
  • Must be accessible from both your web app and scheduler
  • Include protocol (http/https) but no trailing slash
  • Default WAHA port is 3000
string
required
API key for authenticating with your WAHA server.Example:
Notes:
  • Set this in your WAHA server configuration
  • Use a strong, unique key
  • Same key must be used across all services

Authentication Configuration

string
required
Secret key used by Better Auth for session encryption and security.Example:
Requirements:
  • Minimum 32 characters
  • Use random, cryptographically secure string
  • Different for development and production
Generate a secure secret:
string
required
Base URL of your application for authentication callbacks.Development:
Production:
Notes:
  • Must match your actual domain
  • Include protocol (http/https)
  • No trailing slash
  • Update after deploying to production

Email Configuration (Mailgun)

string
required
API key from your Mailgun account for sending emails.Example:
Where to find:
  1. Log in to Mailgun
  2. Go to Settings → API Keys
  3. Copy your Private API key
string
required
Your verified Mailgun domain for sending emails.Example:
Setup:
  1. Add and verify your domain in Mailgun
  2. Configure DNS records (MX, TXT, CNAME)
  3. Wait for verification (usually 24-48 hours)
string
required
Email address to use as sender for system emails.Example:
Requirements:
  • Domain must match MAILGUN_DOMAIN
  • Use a professional, recognizable address
  • Avoid generic terms like “test” or “admin”

Admin Configuration

string
required
Email address for receiving admin notifications.Example:
Used for:
  • New user registration notifications
  • System alerts and errors
  • Password reset notifications
  • Fallback when WhatsApp notifications fail
string
WhatsApp phone number for receiving admin notifications.Example:
Format:
  • Include country code with + prefix
  • No spaces or special characters
  • Must be registered WhatsApp number
Used for:
  • Real-time new user registration alerts
  • Critical system notifications
  • If not set, only email notifications are sent

Optional Variables

UI Configuration

Control visibility of the application footer.Example:
Notes:
  • Must start with NEXT_PUBLIC_ to be available in browser
  • Defaults to showing footer if not set
  • Any value other than “false” shows the footer

Environment File Examples

Development (.env)

Production (Vercel)

Scheduler (.env.production on VPS)

Environment Variables by Service

Web Application (Vercel)

Required for the Next.js web app:

Message Scheduler (VPS)

Required for the background scheduler:
The scheduler only needs database and WAHA access. It doesn’t need auth or email configuration.

Security Best Practices

Secret Generation

Environment File Security

  1. Never commit secrets
  2. Use different secrets per environment
    • Development and production must have different secrets
    • Never reuse API keys across environments
  3. Restrict file permissions
  4. Rotate secrets regularly
    • Update BETTER_AUTH_SECRET quarterly
    • Rotate API keys if compromised
    • Update admin credentials periodically

MongoDB Security

  1. Network Access
    • For Vercel: Allow 0.0.0.0/0 (Vercel uses dynamic IPs)
    • For VPS: Whitelist specific VPS IP address
  2. Strong Passwords
    • Use generated passwords (20+ characters)
    • Include uppercase, lowercase, numbers, special chars
    • Never use common passwords
  3. Database User Permissions
    • Create separate users for dev/prod
    • Grant minimum required permissions
    • Use read-only users for analytics

Troubleshooting

Common Issues

“BETTER_AUTH_SECRET must be set”
“Failed to connect to MongoDB”
“Mailgun authentication failed”
“WAHA API connection refused”

Validation

Validate your environment configuration:

Next Steps

Deploy to Vercel

Deploy the web application

Scheduler Setup

Set up the background scheduler