Required Variables
These environment variables must be set for the application to function correctly.NEXT_PUBLIC_API_URL
The base URL of the backend REST API that MicroCBM connects to.
.env.local
SESSION_SECRET
A secret key used for session management and JWT token validation. Must be a strong, random string.
.env.local
Generate a secure random string using:
openssl rand -base64 32- Minimum 32 characters
- Include uppercase, lowercase, numbers, and symbols
- Never commit to version control
- Use different values for development and production
Environment File Setup
Create a.env.local file in the project root:
.env.local
Environment Files
Next.js supports multiple environment files with different priorities:| File | Description | Priority |
|---|---|---|
.env | Default values for all environments | Lowest |
.env.local | Local overrides (gitignored) | High |
.env.development | Development environment only | Medium |
.env.production | Production environment only | Medium |
.env.development.local | Local development overrides | Highest |
.env.production.local | Local production overrides | Highest |
Variables in
.env.local override all other environment files except .env.*.local.Platform-Specific Configuration
Vercel
Add environment variables in the Vercel dashboard:Select Environments
Choose which environments (Production, Preview, Development) should use each variable.
Netlify
Configure environment variables in Netlify:Docker
Pass environment variables to Docker containers: Using .env file:docker-compose.yml
Development vs Production
Development Environment
.env.development.local
Production Environment
.env.production
Validation
Verify your environment variables are loaded correctly:Never log the actual value of
SESSION_SECRET in production.Backend API Requirements
Expected API Behavior:- The backend must respond to requests at the configured URL
- Free-tier hosting may have 30-60 second cold start times
- The API should support JWT token authentication
- CORS must be configured to allow requests from your frontend domain
Troubleshooting
Environment Variables Not Loading
API Connection Fails
- Verify
NEXT_PUBLIC_API_URLis set correctly - Check that the API is running and accessible
- Ensure CORS is configured on the backend
- Check for firewall or network restrictions
- Allow 30-60 seconds for free-tier API cold starts
Session Issues
- Verify
SESSION_SECRETis set and matches across deployments - Ensure the secret is at least 32 characters
- Check that cookies are enabled in the browser
- Verify the domain and secure settings for production
Security Best Practices
Use Secrets Management
Store sensitive values in your platform’s secrets manager, not in environment files.
Rotate Secrets Regularly
Change
SESSION_SECRET periodically and immediately if compromised.Separate Environments
Use different values for development, staging, and production.
Audit Access
Limit who can view and modify production environment variables.
Next Steps
Deployment Overview
Learn about deployment platforms and strategies
Security
Configure security headers and middleware