Environment Variables
Managing environment variables in ShipKit
Environment Variables
ShipKit uses Zod for type-safe environment variable validation. This ensures runtime safety and provides excellent developer experience with TypeScript integration.
Quick Setup
- Copy the example environment file:
- Generate required secrets:
File Structure
.env.local
- Local development variables (not committed).env.test
- Test environment variables (committed).env.example
- Example variables template (committed)env.schema.ts
- TypeScript schema (committed)
Required Variables
Core Authentication
OAuth Providers
GitHub
Discord
Database
Email Service
Payments
Content Management
Node Environment
Type Safety
Environment variables are validated using Zod schemas:
Environment Management
Local Development
- Initial setup:
- Update variables:
- Edit
.env.local
directly - Use
pnpm db:sync
to sync database configuration
Production (Vercel)
- Add variables:
- Remove variables:
- Pull variables:
Best Practices
-
Security
- Never commit
.env.local
or.env.production
- Use strong, unique secrets for each environment
- Rotate secrets regularly
- Use different values for development and production
- Never commit
-
Documentation
- Keep
.env.example
updated with all variables - Document each variable's purpose and format
- Include links to external service dashboards
- Keep
-
Type Safety
- Always update
env.schema.ts
when adding variables - Use strict validation rules
- Handle required variables explicitly
- Always update
-
Organization
- Group related variables together
- Use clear, descriptive names
- Follow naming conventions consistently
Common Issues
-
Database Connection
- Check DATABASE_URL format
- Verify database credentials
- Confirm database server is running
-
OAuth Configuration
- Verify callback URLs match AUTH_URL
- Check provider credentials
- Confirm OAuth app settings
-
Email Service
- Validate RESEND_API_KEY format
- Check API key permissions
- Monitor email delivery logs
-
Payment Integration
- Verify LemonSqueezy credentials
- Check webhook configuration
- Test payment flows in sandbox mode
Security Considerations
-
Secret Management
- Use a password manager for secrets
- Never share secrets in plain text
- Rotate compromised secrets immediately
-
Access Control
- Limit access to production variables
- Use separate accounts for staging/production
- Audit variable access regularly
-
Monitoring
- Log environment changes
- Monitor for unauthorized access
- Set up alerts for critical changes
Validation Scripts
Run validation: