Configuration

Configure your environment variables to enable authentication, payments, email, analytics, and database features.

Environment Variables Overview

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.

Required
Essentials

  • • Database connection
  • • NextAuth secret
  • • Basic authentication

Optional
Full Features

  • • Stripe payments
  • • Email service
  • • Analytics tracking

Database Configuration

Required
PostgreSQL Database

Configure your PostgreSQL database connection (we recommend Neon for production):

.env
# Database URLs
DATABASE_URL="postgresql://username:password@localhost:5432/rankthis"
PREVIEW_DATABASE_URL="postgresql://username:password@preview-db:5432/rankthis"
DATABASE_URL - Your main database connection
PREVIEW_DATABASE_URL - Optional: Database for preview deployments

🌐 Neon Setup (Recommended)

Create a free database at neon.tech and copy the connection string to your DATABASE_URL.

Authentication Configuration

Required
NextAuth.js Setup

Configure authentication with NextAuth.js secret and providers:

.env
# Authentication
AUTH_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"
AUTH_SECRET - Generate with: openssl rand -base64 32
NEXTAUTH_URL - Your app's URL (production URL for deployed apps)
Google OAuth - Optional: Enable Google sign-in (see setup guide below)
Google OAuth Setup

To enable Google sign-in, create OAuth credentials:

  1. 1. Go to Google Cloud Console
  2. 2. Create a new project or select existing
  3. 3. Enable the Google+ API
  4. 4. Create OAuth 2.0 credentials
  5. 5. Add authorized redirect URIs:
    • http://localhost:3000/api/auth/callback/google
    • https://yourdomain.com/api/auth/callback/google

Stripe Configuration

Optional
Payment Processing

Configure Stripe for subscription billing:

.env
# Stripe Configuration
STRIPE_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_..."
Secret Keys - Get from Stripe Dashboard → Developers → API keys
Webhook Secret - Create webhook endpoint for subscription events
Price IDs - Create products/prices in Stripe Dashboard

⚠️ 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

Optional
Resend Email Service

Configure Resend for transactional emails (welcome, billing, magic links):

.env
# Email Configuration
AUTH_RESEND_KEY="re_..."
FROM_EMAIL="noreply@yourdomain.com"
# Email Settings
COMPANY_NAME="Your SaaS"
SUPPORT_EMAIL="support@yourdomain.com"
AUTH_RESEND_KEY - Get from resend.com
FROM_EMAIL - Email address for outgoing emails (verify domain in Resend)
Company details - Used in email templates and branding

Analytics Configuration

Optional
PostHog Analytics

Configure PostHog for user analytics and event tracking:

.env
# Analytics Configuration
NEXT_PUBLIC_POSTHOG_KEY="phc_..."
NEXT_PUBLIC_POSTHOG_HOST="https://eu.i.posthog.com"
# Optional: Server-side analytics
POSTHOG_HOST="https://eu.i.posthog.com"
PostHog Keys - Get from posthog.com project settings
POSTHOG_HOST - Optional: For server-side analytics and admin dashboard

Complete .env Example

Full Configuration Template

Here's a complete example with all possible environment variables:

.env
1# Database Configuration
2DATABASE_URL="postgresql://username:password@localhost:5432/rankthis"
3
4# Authentication
5AUTH_SECRET="your-generated-secret-key"
6NEXTAUTH_URL="http://localhost:3000"
7
8# Google OAuth (optional)
9AUTH_GOOGLE_ID="your-google-client-id"
10AUTH_GOOGLE_SECRET="your-google-client-secret"
11
12# Email Service
13AUTH_RESEND_KEY="re_..."
14
15# Stripe Configuration
16STRIPE_SECRET_KEY="sk_test_..."
17STRIPE_WEBHOOK_SECRET="whsec_..."
18
19# 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_..."
24
25# Client-side variables
26NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."
27NEXT_PUBLIC_POSTHOG_KEY="phc_..."
28NEXT_PUBLIC_POSTHOG_HOST="https://eu.i.posthog.com"
29
30# Analytics (optional)
31POSTHOG_HOST="https://eu.i.posthog.com"
32
33# Security
34CRON_SECRET="your-cron-secret"
💡 Environment-Specific Tips

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?