Required variables
These variables must be set for the application to function:Database configuration
Your Turso database connection URL.Format:
libsql://[database-name]-[org].turso.ioExample: libsql://invoice-generator-myorg.turso.ioUsed in:app/lib/turso.ts:4- Database client initializationscripts/migrate.mjs:20- Migration script
Authentication token for Turso database access.Format: Long base64-encoded stringUsed in:
app/lib/turso.ts:5- Database client authenticationscripts/migrate.mjs:21- Migration authentication
Optional for local development with
file: URLs, but required for production with remote Turso databases.Authentication configuration
Secret key used by NextAuth.js to encrypt tokens and session data.Format: Random base64 string (minimum 32 characters)Used in: NextAuth.js session encryption and JWT signingHow to generate:Example output:
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6OAuth 2.0 Client ID from Google Cloud Console.Format:
[random-string].apps.googleusercontent.comExample: 123456789-abc123.apps.googleusercontent.comUsed in:auth.ts:14- Google provider configurationauth.config.ts:17- Edge-compatible auth config
- Go to Google Cloud Console
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Select Web application
- Add authorized redirect URIs (see below)
- Copy the Client ID
OAuth 2.0 Client Secret from Google Cloud Console.Format: Random alphanumeric stringUsed in:
auth.ts:15- Google provider configurationauth.config.ts:18- Edge-compatible auth config
Google OAuth redirect URIs
Add these authorized redirect URIs in Google Cloud Console based on your deployment: Local development:The redirect URI must match exactly, including the protocol (
http vs https) and domain.Environment file setup
Development (.env.local)
Create.env.local for local development:
Production (.env.production)
Create.env.production for production deployment:
Platform-specific configuration
Vercel
Add environment variables in Vercel dashboard:- Navigate to your project
- Go to Settings > Environment Variables
- Add each variable with appropriate environment (Production, Preview, Development)
- Redeploy for changes to take effect
- Production:
TURSO_DATABASE_URL=libsql://prod.turso.io - Preview:
TURSO_DATABASE_URL=libsql://preview.turso.io
Docker
Pass environment variables to Docker: Using —env-file:Node.js (systemd)
For systemd services, useEnvironmentFile:
PM2
With PM2, useenv_file in ecosystem.config.js:
Variable validation
The application validates required environment variables at startup: Database URL check (scripts/migrate.mjs:14-17):
- Variable names are spelled correctly
.envfile is in the correct location- Environment file is loaded (use
--env-fileflag if needed)
Security best practices
Use secret managers
For production, use platform-specific secret managers:
- Vercel: Built-in environment variables
- AWS: AWS Secrets Manager or Parameter Store
- GCP: Secret Manager
- Azure: Key Vault
Limit access
- Restrict who can view production environment variables
- Use separate credentials for development and production
- Never log or expose secrets in application code
Troubleshooting
Variables not loading
Symptom: Application throws errors about undefined environment variables Solutions:- Verify
.envfile exists in project root - Check file is named correctly (
.env.localfor dev,.env.productionfor prod) - Use
--env-fileflag explicitly: - Ensure no trailing spaces or quotes in values
Authentication failures
Symptom: OAuth login doesn’t work or shows errors Check:AUTH_SECRETis set and not emptyGOOGLE_CLIENT_IDmatches the one in Google Cloud ConsoleGOOGLE_CLIENT_SECRETis correct- Redirect URI in Google Console matches your deployment URL exactly
Database connection errors
Symptom: Can’t connect to database or migrations fail Verify:TURSO_DATABASE_URLformat is correct (starts withlibsql://)TURSO_AUTH_TOKENis valid and not expired- Database exists:
- Network can reach Turso endpoints (check firewall)
Environment variable reference table
| Variable | Required | Used In | Purpose |
|---|---|---|---|
TURSO_DATABASE_URL | Yes | app/lib/turso.ts:4, scripts/migrate.mjs:20 | Database connection URL |
TURSO_AUTH_TOKEN | Yes* | app/lib/turso.ts:5, scripts/migrate.mjs:21 | Database authentication |
AUTH_SECRET | Yes | NextAuth.js | Session encryption |
GOOGLE_CLIENT_ID | Yes | auth.ts:14, auth.config.ts:17 | OAuth client ID |
GOOGLE_CLIENT_SECRET | Yes | auth.ts:15, auth.config.ts:18 | OAuth secret |
file: URLs, required for remote databases
Next steps
Deploy to Vercel
Quick deployment with environment variables
Self-hosted deployment
Configure environment for self-hosting
Deployment overview
Back to deployment overview