Environment Config
RNCopilot centralizes all environment configuration in a single typed module. The app boots and works without any environment variables configured — all external services degrade gracefully.
Source: src/config/env.ts
Usage
import { env } from '@/config/env';
console.log(env.apiBaseUrl); // 'https://api.example.com'
console.log(env.isDev); // true (in development)
console.log(env.supabaseUrl); // '' (if not configured)env Object
| Property | Type | Default | Description |
|---|---|---|---|
supabaseUrl | string | '' | Supabase project URL |
supabaseAnonKey | string | '' | Supabase anonymous/public key |
apiBaseUrl | string | 'https://api.example.com' | Base URL for the API client |
sentryDsn | string | '' | Sentry DSN for error tracking |
appEnv | 'development' | 'staging' | 'production' | 'development' | Current app environment |
isDev | boolean | computed | true when appEnv === 'development' |
isProd | boolean | computed | true when appEnv === 'production' |
Environment Variables
All environment variables use the EXPO_PUBLIC_ prefix, which makes them available at runtime in Expo:
| Variable | Maps To |
|---|---|
EXPO_PUBLIC_SUPABASE_URL | env.supabaseUrl |
EXPO_PUBLIC_SUPABASE_PUBLISHED_KEY | env.supabaseAnonKey |
EXPO_PUBLIC_API_BASE_URL | env.apiBaseUrl |
EXPO_PUBLIC_SENTRY_DSN | env.sentryDsn |
EXPO_PUBLIC_APP_ENV | env.appEnv |
Variables are read from process.env first, then from expo-constants (Constants.expoConfig.extra), with a fallback to the default value.
.env File
Copy the example file and fill in values as needed:
cp .env.example .env# .env
EXPO_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
EXPO_PUBLIC_SUPABASE_PUBLISHED_KEY=your-anon-key
EXPO_PUBLIC_API_BASE_URL=https://api.your-app.com
EXPO_PUBLIC_SENTRY_DSN=https://your-dsn@sentry.io/123
EXPO_PUBLIC_APP_ENV=developmentThe .env file is gitignored. Each developer maintains their own local copy. The .env.example file is committed and documents all available variables.
Graceful Degradation
The app is designed to work without any environment variables configured:
- Supabase — If
supabaseUrlorsupabaseAnonKeyis empty, the Supabase client initializes gracefully and auth features are disabled. The app boots normally. - API base URL — Falls back to
https://api.example.com. Replace this when connecting to your real backend. - Sentry — If
sentryDsnis empty, error reporting is silently disabled.
Never commit real credentials to version control. The .env file is in .gitignore by default.
validateEnv
A utility function that checks for missing critical variables and returns warnings:
import { validateEnv } from '@/config/env';
const warnings = validateEnv();
// ['EXPO_PUBLIC_SUPABASE_URL is not set', 'EXPO_PUBLIC_SUPABASE_PUBLISHED_KEY is not set']This is useful during app initialization to log warnings in development without crashing in production.