This guide explains how to add and validate environment variables for the Lace Mobile app.
- Add to
src/app/util/config.ts- Add the variable to
cleanEnvinputs (reads fromprocess.env.EXPO_PUBLIC_*) - Add a validator (
str,num, etc.) tocleanEnvschema - Map the validated value into the returned
appConfig
- Add the variable to
- Add to
.env.examplewith an example value - Add to local env files:
.env.developmentand.env.local - CI/Production: Ensure
.env.productionincludes the variable - Validate locally or in CI using the preflight script
Important: All Expo-visible variables must be prefixed with
EXPO_PUBLIC_.
Validation is implemented directly in src/app/util/config.ts using envalid cleanEnv. This file is the single source of truth for environment variables and for the appConfig mapping used at runtime.
src/app/util/config.ts— All env validation andappConfigmappingscripts/validate-environment.ts— Preflight validator (used locally and by CI)ci/mobile/01_check_env.sh— Runs the preflight validator before builds.env.example— Example file with all variables
Add the variable in BOTH the input and the schema of cleanEnv:
const validatedEnvironment = cleanEnv(
{
// ...existing
YOUR_NEW_VARIABLE: process.env.EXPO_PUBLIC_YOUR_NEW_VARIABLE as string,
},
{
// ...existing
YOUR_NEW_VARIABLE: str({ desc: 'What this variable does' }),
},
);
return {
// ...existing
yourNewConfigKey: validatedEnvironment.YOUR_NEW_VARIABLE,
};# Description of what this does
EXPO_PUBLIC_YOUR_NEW_VARIABLE=example-value# .env.development or .env.local
EXPO_PUBLIC_YOUR_NEW_VARIABLE=your-local-value- Ensure
.env.productioncontains the variable - CI runs a preflight validation and fails fast if variables are missing (see below)
- Local (from
apps/lace-mobile):
npm run validate-env
# or
npx tsx scripts/validate-environment.ts- CI runs
ci/mobile/01_check_env.sh, which:- Ensures
apps/lace-mobile/.env.productionexists - Runs
scripts/validate-environment.tswithNODE_ENV=production - Fails the pipeline if validation fails
- Ensures
- Required: omit
defaultand validation fails if missing - Optional: provide a
defaultin the validator
// Required
REQUIRED_VAR: str({ desc: 'This must be provided' }),
// Optional
OPTIONAL_VAR: str({
desc: 'This has a default',
default: 'default-value',
}),- Use clear, descriptive names
- Provide helpful
descvalues for validators - Keep all validation centralized in
config.ts - Document defaults in
.env.example - Validate locally before committing (run the preflight script)
.env.local— Local overrides (gitignored).env.development— Local development defaults.env.example— Example values for all variables.env.production— CI/production values (injected by CI)
- App shows configuration error screen: populate your local
.env.development/.env.localwith the missing variables. - Variable not found: ensure it has the
EXPO_PUBLIC_prefix and is listed in bothcleanEnvinput and schema inconfig.ts. - Build fails in CI: verify
.env.productionis generated from secrets and includes all required variables.