Configuration
Configure your environment variables to enable authentication, payments, email, analytics, and database features.
Your .env file contains all the configuration needed to run RankThis. Each service can be configured independently - start with the essentials and add more as needed.
RequiredEssentials
- • Database connection
- • NextAuth secret
- • Basic authentication
OptionalFull Features
- • Stripe payments
- • Email service
- • Analytics tracking
Database Configuration
Configure your PostgreSQL database connection (we recommend Neon for production):
# Database URLsDATABASE_URL="postgresql://username:password@localhost:5432/rankthis"PREVIEW_DATABASE_URL="postgresql://username:password@preview-db:5432/rankthis"
🌐 Neon Setup (Recommended)
Create a free database at neon.tech and copy the connection string to your DATABASE_URL.
Authentication Configuration
Configure authentication with NextAuth.js secret and providers:
# AuthenticationAUTH_SECRET="your-secret-key-here"NEXTAUTH_URL="http://localhost:3000"# Google OAuth (optional but recommended)AUTH_GOOGLE_ID="your-google-client-id"AUTH_GOOGLE_SECRET="your-google-client-secret"
openssl rand -base64 32To enable Google sign-in, create OAuth credentials:
- 1. Go to Google Cloud Console
- 2. Create a new project or select existing
- 3. Enable the Google+ API
- 4. Create OAuth 2.0 credentials
- 5. Add authorized redirect URIs:
- •
http://localhost:3000/api/auth/callback/google - •
https://yourdomain.com/api/auth/callback/google
- •
Stripe Configuration
Configure Stripe for subscription billing:
# Stripe ConfigurationSTRIPE_SECRET_KEY="sk_test_..."NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."STRIPE_WEBHOOK_SECRET="whsec_..."# Stripe Price IDs (Tiered Subscriptions)STRIPE_PRICE_PRO_MONTHLY="price_..."STRIPE_PRICE_PRO_YEARLY="price_..."STRIPE_PRICE_ULTRA_MONTHLY="price_..."STRIPE_PRICE_ULTRA_YEARLY="price_..."
⚠️ Webhook Setup Required
Create a webhook endpoint at /api/webhooks/stripe in your Stripe Dashboard to handle subscription events. See the Stripe guide for details.
Email Configuration
Configure Resend for transactional emails (welcome, billing, magic links):
# Email ConfigurationAUTH_RESEND_KEY="re_..."FROM_EMAIL="noreply@yourdomain.com"# Email SettingsCOMPANY_NAME="Your SaaS"SUPPORT_EMAIL="support@yourdomain.com"
Analytics Configuration
Configure PostHog for user analytics and event tracking:
# Analytics ConfigurationNEXT_PUBLIC_POSTHOG_KEY="phc_..."NEXT_PUBLIC_POSTHOG_HOST="https://eu.i.posthog.com"# Optional: Server-side analyticsPOSTHOG_HOST="https://eu.i.posthog.com"
Complete .env Example
Here's a complete example with all possible environment variables:
1# Database Configuration2DATABASE_URL="postgresql://username:password@localhost:5432/rankthis"34# Authentication5AUTH_SECRET="your-generated-secret-key"6NEXTAUTH_URL="http://localhost:3000"78# Google OAuth (optional)9AUTH_GOOGLE_ID="your-google-client-id"10AUTH_GOOGLE_SECRET="your-google-client-secret"1112# Email Service13AUTH_RESEND_KEY="re_..."1415# Stripe Configuration16STRIPE_SECRET_KEY="sk_test_..."17STRIPE_WEBHOOK_SECRET="whsec_..."1819# Stripe Price IDs (Tiered Subscriptions)20STRIPE_PRICE_PRO_MONTHLY="price_..."21STRIPE_PRICE_PRO_YEARLY="price_..."22STRIPE_PRICE_ULTRA_MONTHLY="price_..."23STRIPE_PRICE_ULTRA_YEARLY="price_..."2425# Client-side variables26NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."27NEXT_PUBLIC_POSTHOG_KEY="phc_..."28NEXT_PUBLIC_POSTHOG_HOST="https://eu.i.posthog.com"2930# Analytics (optional)31POSTHOG_HOST="https://eu.i.posthog.com"3233# Security34CRON_SECRET="your-cron-secret"
Development vs Production
- • Use test keys for Stripe in development
- • Set NEXTAUTH_URL to your production domain when deployed
- • Use separate databases for development and production
Security Best Practices
- • Never commit .env files to version control
- • Use different secrets for each environment
- • Rotate API keys regularly
Configuration Complete!
Your environment is configured. Ready to deploy to production?