Overview
Your Bible requires several environment variables to function properly. Copy.env.example to .env and configure each variable according to this guide.
Variable Categories
API.Bible
Bible content API configuration
Authentication
Better Auth and OAuth settings
Database
PostgreSQL and Convex configuration
AI & Services
Gemini AI, Redis, and other services
Required Variables
API.Bible Configuration
Base URL for the API.Bible service.Value:
https://api.scripture.api.bible/v1Usage: All Bible content requests (translations, chapters, search)How to get:
This is a fixed URL. Use the value above.Your API.Bible API key for authentication.Example:
abc123def456...Usage: Authenticates requests to API.BibleHow to get:- Visit API.Bible
- Sign up for a free account
- Navigate to “API Keys” section
- Create a new API key
- Copy the key to your
.envfile
Authentication Configuration
Secret key for Better Auth session encryption and security.Example:
your_random_secret_key_hereUsage: Encrypts authentication tokens and sessionsHow to generate:The base URL of your application for authentication callbacks.Development:
http://localhost:5173Production: https://yourdomain.comUsage: OAuth redirects, authentication callbacksUpdate this value when deploying to production.
Database Configuration
PostgreSQL connection string for Better Auth.Format:
postgresql://user:password@host:port/database?sslmode=requireExample (Neon): postgresql://user:pass@ep-abc123.us-east-2.neon.tech/yourbible?sslmode=requireExample (Local): postgresql://localhost/yourbibleUsage: Stores user accounts, sessions, and auth dataHow to get:- Neon (Recommended)
- Local PostgreSQL
- Visit Neon.tech
- Create a free account
- Create a new project
- Copy the connection string from your dashboard
- Ensure
?sslmode=requireis appended
Your Convex deployment identifier.Example:
prod:my-app-123Usage: Identifies your Convex backend deploymentHow to get:
Automatically set when you run npx convex dev. You can also find it in your Convex dashboard.This is auto-generated. Don’t manually edit unless necessary.
Your Convex backend URL for client connections.Example:
https://your-project-123.convex.cloudUsage: Client-side Convex SDK connectionHow to get:- Run
npx convex dev - Convex will automatically add this to your
.env - Or copy from Convex dashboard under “Settings”
AI Configuration
Google Gemini model to use for story generation.Recommended:
gemini-1.5-flashAlternative: gemini-1.5-pro (higher quality, higher cost)Usage: AI-powered story generationModel Comparison:gemini-1.5-flash: Fast, cost-effective, good qualitygemini-1.5-pro: Best quality, slower, more expensive
Your Google Gemini API key.Example:
AIzaSy...Usage: Authenticates requests to Google Gemini AIHow to get:- Visit Google AI Studio
- Sign in with your Google account
- Click “Get API Key”
- Create a new API key or use existing one
- Copy the key to your
.envfile
Redis/Upstash Configuration
Redis is used for rate limiting story generation (5 stories per user per day) to manage API costs.
Redis connection URL.Example:
redis://default:password@host:portUsage: Rate limiting for story generationHow to get:- Visit Upstash
- Create account and new Redis database
- Copy Redis URL from dashboard
Upstash KV (Key-Value) connection URL.Example:
https://your-db.upstash.ioUsage: Alternative Redis connection methodHow to get:
Found in Upstash dashboard under “REST API” section.Upstash REST API URL for Redis operations.Example:
https://your-db.upstash.ioUsage: HTTP-based Redis operationsHow to get:
Copy from Upstash dashboard → Your database → REST API → UPSTASH_REDIS_REST_URLAuthentication token for Upstash REST API.Example:
AXX1AAIncDE...Usage: Authenticates Redis REST API requestsHow to get:
Copy from Upstash dashboard → Your database → REST API → UPSTASH_REDIS_REST_TOKENRead-only token for Upstash REST API.Example:
AnE1AAIncDE...Usage: Read-only Redis operations (security best practice)How to get:
Copy from Upstash dashboard → Your database → REST API → UPSTASH_REDIS_REST_TOKEN_READ_ONLYOptional Variables
GitHub OAuth (Optional)
GitHub OAuth application client ID.Usage: Enables “Sign in with GitHub” functionalityHow to get:
- Go to GitHub Settings → Developer settings → OAuth Apps
- Click “New OAuth App”
- Fill in application details:
- Application name: Your Bible
- Homepage URL:
http://localhost:5173(dev) or your production URL - Authorization callback URL:
http://localhost:5173/api/auth/callback/github
- Click “Register application”
- Copy the Client ID
If not set, GitHub authentication will be disabled. Users can still sign in with email/password.
GitHub OAuth application client secret.Usage: Authenticates GitHub OAuth requestsHow to get:
- In your GitHub OAuth App settings
- Click “Generate a new client secret”
- Copy the secret immediately (it won’t be shown again)
UploadThing (Future Feature)
UploadThing API token for file uploads.Usage: Reserved for future file upload features (e.g., profile pictures, attachments)Status: Not currently used in the applicationHow to get:
- Visit UploadThing
- Create account and project
- Copy token from dashboard
This is optional and not required for current functionality.
Environment Files
Development (.env)
Production (.env.production)
Production Environment Configuration
Production Environment Configuration
For production deployment:
- Create
.env.production(do not commit to git) - Update URLs to production values:
BETTER_AUTH_URL→ Your production domainDATABASE_URL→ Production PostgreSQL instanceCONVEX_DEPLOYMENT→ Production Convex deployment
- Use stronger secrets
- Enable SSL/TLS where applicable
- Set appropriate rate limits
- All secrets are unique (not reused from development)
- Database connection uses SSL (
?sslmode=require) - API keys have appropriate rate limits
- GitHub OAuth callback URL matches production domain
- Better Auth URL uses HTTPS
Validation
The application validates required environment variables at startup. Missing or invalid variables will cause the application to fail with descriptive error messages.Checking Your Configuration
Testing Individual Services
Troubleshooting
Variable Not Found
Variable Not Found
Problem: Environment variable is not being readSolutions:
- Ensure
.envfile exists in project root - Restart development server after editing
.env - Check for typos in variable names
- Verify no extra spaces around
=sign - For client-side variables, ensure
VITE_prefix
Invalid API Key
Invalid API Key
Problem: API requests failing with authentication errorsSolutions:
- Verify API key is correct (no extra spaces)
- Check key hasn’t been revoked or expired
- Confirm key has necessary permissions
- Regenerate key if needed
Database Connection Failed
Database Connection Failed
Problem: Cannot connect to PostgreSQLSolutions:
- Verify connection string format is correct
- Check database server is running
- Test connection with
psqlor database GUI - Ensure SSL mode is correct (
?sslmode=requirefor Neon) - Verify firewall allows connection
Convex Not Connecting
Convex Not Connecting
Problem: Convex sync not workingSolutions:
- Ensure
npx convex devis running - Verify
VITE_CONVEX_URLis correct - Check Convex deployment status in dashboard
- Clear browser cache and reload
- Restart both Convex and development server
Rate Limiting Not Working
Rate Limiting Not Working
Problem: Story generation rate limit not appliedSolutions:
- Verify all Redis environment variables are set
- Test Redis connection in Upstash dashboard
- Check
KV_REST_API_TOKENis valid - Review rate limit configuration in
src/lib/redis.ts
Security Best Practices
Never Commit Secrets
- Add
.envto.gitignore(already configured) - Use
.env.exampleas template without real values - Never commit API keys, secrets, or passwords
Use Strong Secrets
- Generate random secrets:
openssl rand -base64 32 - Use different secrets for development and production
- Rotate secrets periodically
Limit API Key Permissions
- Use read-only keys where possible
- Set rate limits on API keys
- Restrict API keys to specific domains in production
Related Documentation
Local Setup
Complete guide to setting up your development environment
Integrations
Detailed documentation for each external service
Deployment
Deploying Your Bible to production
Troubleshooting
Common issues and solutions