Overview
Villa Buena E-Commerce uses environment variables to configure API endpoints, authentication settings, and other runtime configurations. The project uses Vite’s environment variable system, which requires variables to be prefixed withVITE_ to be exposed to the client.
Required Variables
API Configuration
The base URL for the backend API server.Usage: Configured in
src/services/api.js as the baseURL for axios instances.Example values:- Development:
http://localhost:3000/api - Production:
https://api.villabuena.com
Authentication Configuration
Auth0 credentials are currently hardcoded in
src/main.jsx. For production deployments, these should be moved to environment variables.Current Auth0 Setup
The application currently uses the following Auth0 configuration (defined insrc/main.jsx:16-18):
Recommended Environment Variables (Future)
For better security and environment separation, consider adding:Auth0 tenant domainExample:
dev-rafaelval.us.auth0.comAuth0 application client IDExample:
ripKJ8Jjq1c3gLEOcusOGUTBTFVGoVdGAuth0 API audience identifier (if using API authorization)
Environment Files
File Structure
Create environment-specific files in your project root:Example Configuration
Create a.env file in the project root:
Accessing Environment Variables
In Application Code
Access environment variables using Vite’simport.meta.env object:
Built-in Vite Variables
Vite provides several built-in environment variables:The mode the app is running in (
development, production, or custom modes)Whether the app is running in development mode
Whether the app is running in production mode
The base URL the app is being served from
Environment-Specific Configuration
Development Mode
When runningnpm run dev, Vite loads:
.env- Base configuration.env.local- Local overrides.env.development- Development-specific.env.development.local- Local development overrides
Production Mode
When runningnpm run build, Vite loads:
.env- Base configuration.env.local- Local overrides.env.production- Production-specific.env.production.local- Local production overrides
Best Practices
Document all variables
Maintain a
.env.example file with all required variables and their descriptions.Troubleshooting
Variables not loading
- Ensure variables are prefixed with
VITE_ - Restart the dev server after changing
.envfiles - Check that
.envfiles are in the project root, not in subdirectories
Variables showing as undefined
- Verify the variable name is spelled correctly
- Make sure the
.envfile is not in.gitignorefor required config files - Check that you’re using
import.meta.env.VARIABLE_NAME, notprocess.env.VARIABLE_NAME
