Environment Variables
Environment variables let you store configuration and secrets that your app needs, without hardcoding them into your source code.When to Use Environment Variables
API Keys
Third-party service credentials
Configuration
Feature flags, URLs, settings
Secrets
Sensitive data that shouldn’t be in code
Environment-Specific
Different values for dev/staging/prod
Environment Variables by Backend Type
How you manage environment variables depends on which backend system you’re using.Which backend am I using? If you see a “Database” button in the preview header, you’re on Liquid Backend. Otherwise, you’re using Supabase. See Backend Systems.
Liquid Backend (Specular)
With Liquid Backend, environment variables are split between frontend and backend:Frontend Variables
For variables used in your React Native code:
Access in your code:
Backend Variables (Server-Side Secrets)
For secrets that should never be exposed to the frontend: Server-side secrets are configured through Specular:- When you request features that need secrets (e.g., “Add AI chat using OpenAI”), the AI prompts you for the key
- Secrets are stored securely in Specular’s backend
- They’re never exposed to your frontend code
Supabase
With Supabase, the database connection is handled automatically via OAuth integration—no manual API key configuration required.Supabase Connection
Supabase credentials are managed through OAuth:Additional Environment Variables
For other environment variables (not Supabase credentials), use More → Environment Variables:Server-Side Secrets with Supabase
For Supabase, server-side secrets should be stored in Edge Functions:- Create an Edge Function in Supabase Dashboard
- Add secrets via Supabase CLI:
- Access in your Edge Function:
Using Environment Variables in Code
Accessing Variables
All frontend environment variables are accessed the same way:With Default Values
In AI Prompts
Tell the AI to use environment variables:Common Environment Variables
For All Projects
| Variable | Purpose | Safe for Frontend? |
|---|---|---|
GOOGLE_MAPS_API_KEY | Google Maps API | ✅ Yes (with restrictions) |
SENTRY_DSN | Error tracking | ✅ Yes |
POSTHOG_API_KEY | Analytics | ✅ Yes |
For Liquid Backend Projects
| Variable | Where Stored | Notes |
|---|---|---|
| Frontend keys | Natively Env Vars | Via More → Environment Variables |
| Server secrets | Specular | Configured via AI prompts |
For Supabase Projects
| Item | How It’s Handled |
|---|---|
| Supabase connection | Automatic via OAuth |
| Additional frontend vars | More → Environment Variables |
| Server secrets | Supabase Edge Function secrets |
Best Practices
Never hardcode secrets
Never hardcode secrets
API keys, passwords, and tokens should always be in environment variables, not in your code.
Use descriptive names
Use descriptive names
Use clear names like
STRIPE_PUBLIC_KEY instead of KEY1Separate frontend and backend secrets
Separate frontend and backend secrets
Only public keys belong in frontend environment variables. Server-side secrets go in your backend.
Document required variables
Document required variables
Keep track of which environment variables your app needs for deployment.
Environment Differences
Environment variables can differ between development and production:| Environment | Purpose |
|---|---|
| Development | Testing and building features |
| Production | Live app used by real users |
When you deploy, make sure production environment variables are set correctly.
Troubleshooting
Variable returns undefined
Variable returns undefined
- Check the variable name matches exactly (case-sensitive)
- Ensure you saved after adding the variable
- Reload the preview after changes
API key not working
API key not working
- Verify the key is correct (copy-paste from source)
- Check if the key has proper permissions/scopes
Secret exposed in code
Secret exposed in code
- Move server-side secrets to backend (Specular or Edge Functions)
- Use frontend environment variables only for public keys
- Check git history and rotate exposed secrets