Environment Variables
Complete reference guide for all environment variables used in the WhatsApp WAHA Dashboard.Quick Start
Copy the example environment file:Required Variables
Database Configuration
MongoDB connection string for storing application data.Format: Notes:
mongodb+srv://username:[email protected]/database-nameExample:- 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
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
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
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
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)
API key from your Mailgun account for sending emails.Example:Where to find:
- Log in to Mailgun
- Go to Settings → API Keys
- Copy your Private API key
Your verified Mailgun domain for sending emails.Example:Setup:
- Add and verify your domain in Mailgun
- Configure DNS records (MX, TXT, CNAME)
- Wait for verification (usually 24-48 hours)
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
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
WhatsApp phone number for receiving admin notifications.Example:Format:
- Include country code with + prefix
- No spaces or special characters
- Must be registered WhatsApp number
- 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:| Variable | Purpose |
|---|---|
DATABASE_URL | Database connection |
WAHA_API_URL | WhatsApp API access |
WAHA_API_KEY | WhatsApp API authentication |
BETTER_AUTH_SECRET | Session encryption |
BETTER_AUTH_URL | Auth callbacks |
MAILGUN_API_KEY | Email sending |
MAILGUN_DOMAIN | Email domain |
FROM_EMAIL | Sender address |
ADMIN_EMAIL | Admin notifications |
ADMIN_PHONE_NUMBER | WhatsApp notifications (optional) |
NEXT_PUBLIC_SHOW_FOOTER | UI configuration (optional) |
Message Scheduler (VPS)
Required for the background scheduler:| Variable | Purpose |
|---|---|
DATABASE_URL | Database connection |
WAHA_API_URL | WhatsApp API access |
WAHA_API_KEY | WhatsApp API authentication |
The scheduler only needs database and WAHA access. It doesn’t need auth or email configuration.
Security Best Practices
Secret Generation
Environment File Security
-
Never commit secrets
-
Use different secrets per environment
- Development and production must have different secrets
- Never reuse API keys across environments
-
Restrict file permissions
-
Rotate secrets regularly
- Update
BETTER_AUTH_SECRETquarterly - Rotate API keys if compromised
- Update admin credentials periodically
- Update
MongoDB Security
-
Network Access
- For Vercel: Allow
0.0.0.0/0(Vercel uses dynamic IPs) - For VPS: Whitelist specific VPS IP address
- For Vercel: Allow
-
Strong Passwords
- Use generated passwords (20+ characters)
- Include uppercase, lowercase, numbers, special chars
- Never use common passwords
-
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”Validation
Validate your environment configuration:Next Steps
Deploy to Vercel
Deploy the web application
Scheduler Setup
Set up the background scheduler