Next.js
Environment variable configuration for Next.js standalone deployment
This configuration is ideal for traditional hosting, Docker deployments, or development environments. Next.js standalone mode provides flexibility for various hosting providers.
🚀 Core Application Settings
Variable | Description | Example | Required |
---|---|---|---|
BETTER_AUTH_SECRET | Secret key for Better Auth session encryption | your-32-character-secret-key | ✅ |
BETTER_AUTH_URL | Base URL of your application | https://yourdomain.com | ✅ |
NEXT_PUBLIC_APP_URL | Public URL for client-side usage | https://yourdomain.com | ✅ |
📧 Email Configuration
Variable | Description | Example | Required |
---|---|---|---|
RESEND_API_KEY | API key for Resend email service | re_123456789 | ✅ |
RESEND_AUDIENCE_ID | Audience ID for newsletter functionality | aud_123456789 | ❌ |
🔐 OAuth Provider Settings
GitHub OAuth
Variable | Description | Example | Required |
---|---|---|---|
GITHUB_CLIENT_ID | GitHub App Client ID | a629723d24c123456 | ❌ |
GITHUB_CLIENT_SECRET | GitHub App Client Secret | abc123def456ghi789jkl012 | ❌ |
Google OAuth
Variable | Description | Example | Required |
---|---|---|---|
GOOGLE_CLIENT_ID | Google OAuth Client ID | 123456789-abc123.apps.googleusercontent.com | ❌ |
GOOGLE_CLIENT_SECRET | Google OAuth Client Secret | GOCSPX-abc123def456ghi789 | ❌ |
💳 Payment Integration (Stripe)
Variable | Description | Example | Required |
---|---|---|---|
STRIPE_SECRET_KEY | Stripe secret key for server-side operations | sk_test_123... or sk_live_123... | ❌ |
STRIPE_WEBHOOK_SECRET | Webhook endpoint secret for Stripe events | whsec_123456789 | ❌ |
NEXT_PUBLIC_PRICE_ID_PRO_MONTHLY | Stripe price ID for monthly pro plan | price_123456789 | ❌ |
NEXT_PUBLIC_PRICE_ID_PRO_YEARLY | Stripe price ID for yearly pro plan | price_987654321 | ❌ |
NEXT_PUBLIC_PRICE_ID_LIFETIME | Stripe price ID for lifetime plan | price_555666777 | ❌ |
📁 Storage Configuration
Variable | Description | Example | Required |
---|---|---|---|
NEXT_PUBLIC_AVATARS_BUCKET_NAME | S3 bucket name for avatar uploads | my-app-avatars | ❌ |
☁️ AWS Infrastructure (if using AWS services)
Variable | Description | Example | Required |
---|---|---|---|
AWS_ACCESS_KEY_ID | AWS access key for S3 and other services | AKIAIOSFODNN7EXAMPLE | ❌ |
AWS_SECRET_ACCESS_KEY | AWS secret key for authentication | wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY | ❌ |
🌍 Cloudflare Integration (if using Cloudflare services)
Variable | Description | Example | Required |
---|---|---|---|
CLOUDFLARE_API_TOKEN | Cloudflare API token for DNS and other services | abc123def456ghi789jkl012 | ❌ |
CLOUDFLARE_DEFAULT_ACCOUNT_ID | Cloudflare account ID | a1b2c3d4e5f6g7h8i9j0 | ❌ |
📝 Example .env File
# Core Application
BETTER_AUTH_SECRET=your-32-character-secret-key-here
BETTER_AUTH_URL=http://localhost:3000
NEXT_PUBLIC_APP_URL=http://localhost:3000
# Email Service
RESEND_API_KEY=re_123456789
RESEND_AUDIENCE_ID=aud_123456789
# OAuth Providers
GITHUB_CLIENT_ID=Iv1.a629723d24c123456
GITHUB_CLIENT_SECRET=abc123def456ghi789jkl012
GOOGLE_CLIENT_ID=123456789-abc123.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-abc123def456ghi789
# Payment Processing
STRIPE_SECRET_KEY=sk_test_123...
STRIPE_WEBHOOK_SECRET=whsec_123456789
NEXT_PUBLIC_PRICE_ID_PRO_MONTHLY=price_123456789
NEXT_PUBLIC_PRICE_ID_PRO_YEARLY=price_987654321
NEXT_PUBLIC_PRICE_ID_LIFETIME=price_555666777
# Storage
NEXT_PUBLIC_AVATARS_BUCKET_NAME=my-app-avatars
# AWS (Optional)
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
# Cloudflare (Optional)
CLOUDFLARE_API_TOKEN=abc123def456ghi789jkl012
CLOUDFLARE_DEFAULT_ACCOUNT_ID=a1b2c3d4e5f6g7h8i9j0
🛠️ Development vs Production
Development Environment
- Use
http://localhost:3000
for local URLs - Use Stripe test keys (starting with
sk_test_
) - OAuth redirect URIs should point to localhost
Production Environment
- Use your actual domain for all URLs
- Use Stripe live keys (starting with
sk_live_
) - Configure OAuth providers with production redirect URIs
- Ensure all secrets are properly secured and rotated regularly
🔧 Next Steps
After setting up your environment variables:
- Test authentication - Verify OAuth providers work correctly
- Test payments - Ensure Stripe integration functions properly
- Test email - Confirm email sending works with your provider
- Deploy - Deploy to your chosen hosting platform
Your Next.js application is now ready for development and deployment! 🎉