Overview
Environment variables allow you to store secrets, API keys, and configuration outside your code. Supabase provides both built-in environment variables and custom secrets management.Built-in Environment Variables
Supabase automatically provides these environment variables to all functions:Access Built-in Variables
Built-in variables are automatically configured and don’t need to be set manually.
Custom Environment Variables
Set Secrets
Set custom secrets using the CLI:Set from File
Set multiple secrets from a file:List Secrets
View all configured secrets (values are hidden):Unset Secrets
Remove a secret:Using Environment Variables
In Your Functions
Access environment variables withDeno.env.get():
With Type Safety
Create a helper for type-safe environment variables:Local Development
Create Local Environment File
Create.env.local for local development:
.gitignore:
Use Local Environment Variables
Serve functions with local environment:Example Local Setup
Create a complete local environment:Real-World Examples
OpenAI Integration
Securely use OpenAI API:Stripe Webhooks
Verify Stripe webhook signatures:Email with Resend
Send emails securely:Database Connection
Connect directly to PostgreSQL:CI/CD Integration
GitHub Actions
Set secrets in GitHub Actions:- Go to Settings > Secrets and variables > Actions
- Add each secret:
SUPABASE_ACCESS_TOKENPROJECT_IDOPENAI_API_KEYSTRIPE_SECRET
Environment-Specific Secrets
Use different secrets for staging and production:Best Practices
Never Hardcode Secrets
Validate Environment Variables
Check variables at startup:Use .env.example
Provide a template for developers:Rotate Secrets Regularly
Update secrets periodically:Troubleshooting
Secret Not Available
If a secret isn’t available:-
Check if set:
-
Set the secret:
-
Redeploy the function:
Local vs Production Differences
If behavior differs between local and production:-
Compare secrets:
- Ensure consistency between environments
- Test with production values locally when debugging
Next Steps
Debugging
Debug and monitor your Edge Functions
Deploy Functions
Learn deployment strategies
