Environment Variables
Configure environment variables to manage API keys, endpoints, and environment-specific settings.Understanding Environment Variables
The starter usesEXPO_PUBLIC_ prefixed environment variables that are:
- Validated with Zod schemas
- Available at build time and runtime
- Environment-specific (development, preview, production)
Environment Variable Schema
All environment variables are defined inpackages/config/src/env.ts:
Local Development Setup
1. Create .env File
Create a.env file in the repository root:
2. Add to .gitignore
Ensure.env is in .gitignore:
3. Restart Development Server
After creating or modifying.env:
Environment-Specific Configuration
Development Environment
For local development:Preview Environment
For testing builds:Production Environment
For production builds:EAS Secrets (Recommended for Production)
For EAS builds, use EAS Secrets instead of committing sensitive values.Create Secrets
List Secrets
Delete Secrets
Build Profile Environment Variables
You can also set environment variables ineas.json for each build profile:
eas.json env values.
Accessing Environment Variables
In Code
Import from@amisi/config:
Available Helpers
Required Variables by Adapter
Firebase Adapter
Required when usingauth.adapter: "firebase":
RevenueCat Adapter
Required when usingsubscriptions.adapter: "revenuecat":
Mock Adapters
No environment variables required when using mock adapters.Validation
Environment variables are validated on app startup using Zod schemas.Validation Errors
If validation fails, you’ll see detailed error messages:Adding New Variables
To add a new environment variable:- Update schema in
packages/config/src/env.ts:
- Update TypeScript types (automatic from Zod):
- Add to .env:
- Access in code:
Security Best Practices
1. Never Commit Secrets
- Add
.envto.gitignore - Use EAS Secrets for sensitive values
- Use
.env.examplefor documentation
2. Use EAS Secrets for Production
3. Restrict API Keys
- Use Firebase API key restrictions
- Use RevenueCat environment-specific keys
- Rotate keys regularly
4. Environment Separation
- Use different Firebase projects for dev/prod
- Use different RevenueCat projects for dev/prod
- Never use production keys in development
Example .env.example
Create.env.example for documentation:
Troubleshooting
Variables Not Loading
Solution: Restart the development server:Validation Errors
Solution: Check that all required variables are set and match the schema format.EAS Build Missing Variables
Solution: Ensure variables are either:- Set as EAS Secrets, OR
- Defined in
eas.jsonenv block
Variables Undefined at Runtime
Solution: Ensure variables haveEXPO_PUBLIC_ prefix for client-side access.