Overview
BoxApp uses environment variables to configure the connection to Supabase and other runtime settings. All environment variables are prefixed withVITE_ to make them available in the browser through Vite’s build process.
Configuration File
Environment variables are stored in a.env file in the project root:
.env.example
Required Variables
The URL of your Supabase project. This is the base endpoint for all API requests.Format:
https://your-project-id.supabase.coLocal development: http://localhost:54321 (when using Supabase local development)Example:The anonymous (public) API key for your Supabase project. This key is safe to use in browser code as it respects Row Level Security policies.Format: Long JWT token string (starts with
eyJ...)Where to find: Supabase Dashboard → Settings → API → Project API keys → anon publicExample:Setup Instructions
Get Supabase credentials
For local development:This outputs your local credentials including the API URL and anon key.For production or cloud development:
- Go to your Supabase project dashboard
- Navigate to Settings → API
- Copy the “Project URL” and “anon public” key
Usage in Code
Environment variables are accessed throughimport.meta.env in Vite:
src/lib/supabaseClient.ts
The Supabase client initialization includes validation to warn you if credentials are missing. Check your browser console for these warnings.
Environment-Specific Configuration
Local Development
Use Supabase local development for testing:.env.local
Staging Environment
Connect to a staging Supabase project:.env.staging
Production Environment
For production deployments (Vercel, Netlify, etc.), set environment variables through your hosting platform’s dashboard.Security Best Practices
Git Security
The.env file is excluded from version control:
.gitignore
.env.example should be committed, with placeholder values.
API Key Types
Supabase provides different API keys:| Key Type | Usage | Safe for Frontend? |
|---|---|---|
anon (public) | Client-side requests | ✅ Yes - Protected by RLS |
service_role | Server-side admin tasks | ❌ No - Bypasses RLS |
Validation
Verify your environment variables are loaded correctly:Troubleshooting
Variables not loading
Symptoms:undefined values for environment variables
Solutions:
- Ensure variables are prefixed with
VITE_ - Restart dev server after changing
.env - Check
.envfile is in project root - Verify no syntax errors in
.env(no quotes needed)
Connection errors
Symptoms: “Failed to connect to Supabase” errors Solutions:- Verify URL format is correct (no trailing slashes)
- Check anon key is complete (they’re very long)
- For local dev, ensure
npx supabase startis running - Test connection in browser network tab