Overview
The MLM CMMS application requires specific environment variables to connect to Supabase and enable push notifications. This guide covers the complete environment setup process for both development and production environments.All environment variables must be prefixed with
VITE_ to be accessible in the Vite-based React application.Prerequisites
Before setting up environment variables, ensure you have:Supabase Project Created
Create a new Supabase project at supabase.com and note your project reference ID.
Required Environment Variables
Core Configuration
Create a.env file in the project root with the following variables:
Obtaining Supabase Credentials
The anon key is safe to use in frontend code. Never use the service_role key in frontend environment variables.
Generating VAPID Keys for Push Notifications
VAPID keys are required for Web Push notifications:Set Private Key in Supabase
The
privateKey must be configured as a secret in Supabase Edge Functions (covered in Supabase Configuration).Environment-Specific Configuration
Development Environment
For local development:http://localhost:5173 (or the port shown in terminal).
QA Environment
For QA/staging builds:Production Environment
For production deployments:Security Best Practices
Never Commit Secrets
Ensure
.env, .env.qa, and .env.production are in your .gitignore file.Use Anon Key Only
Frontend code should only use the anonymous key. Service role keys are for server-side operations only.
Rotate Keys Regularly
Rotate API keys and VAPID keys periodically, especially after team member departures.
Environment Separation
Use different Supabase projects for dev, QA, and production to prevent data leakage.
Verification
After setting up your environment variables:Troubleshooting
”Invalid API key” Error
- Verify that you copied the complete anon key without truncation
- Ensure the key is prefixed with
VITE_ - Check that the Supabase URL matches your project
Environment Variables Not Loading
- Restart the Vite dev server after changing
.envfiles - Verify the
.envfile is in the project root directory - Ensure variable names are prefixed with
VITE_
Push Notifications Not Working
- Verify the VAPID public key is correctly set in
.env - Ensure the corresponding private key is configured in Supabase Edge Functions
- Check that your site is served over HTTPS (required for push notifications)
Next Steps
Database Setup
Configure your Supabase database by executing the SQL modules in the correct order.