Environment Variables & Configuration
Configure type-safe environment variables with T3 Env. Learn how to securely manage database credentials, authentication secrets, and API keys for local and production environments.
Vibestacks uses T3 Env for type-safe environment variables. This means you'll get clear error messages if any required variables are missing or incorrectly formatted - no more silent failures.
Why type-safe env variables matter
Without T3 Env, it's easy to accidentally expose server-side secrets to the browser - a common mistake that can leak API keys and database credentials. Learn how we prevent this in Type-Safe Environment Variables.
Quick Start
Copy the example environment file to create your local configuration:
cp .env.example .env.localOpen .env.local in your editor and configure each variable as described below.
Never commit secrets
The .env.local file is gitignored by default. Never commit files containing secrets like API keys or database credentials to version control.
Core Variables
These variables are required for the application to start.
Database
| Variable | Required | Description |
|---|---|---|
DATABASE_URL | ✅ | PostgreSQL connection string |
Your database connection string. For local development with Docker, use:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/vibestacks"For production, use your hosted database URL from Neon, Supabase, or another PostgreSQL provider.
Connection string format
The format is: postgresql://USER:PASSWORD@HOST:PORT/DATABASE
Authentication
| Variable | Required | Description |
|---|---|---|
BETTER_AUTH_SECRET | ✅ | Secret key for signing session cookies |
A secure random string used by Better Auth to sign and verify session cookies. Generate one with:
openssl rand -base64 32Keep this secret
Never share or expose this value. If compromised, rotate it immediately - this will invalidate all existing user sessions.
Application URL
| Variable | Required | Description |
|---|---|---|
NEXT_PUBLIC_SITE_URL | ✅ | The base URL of your application |
The public URL where your app is accessible. This is used for generating links, OAuth callbacks, and metadata.
NEXT_PUBLIC_SITE_URL=http://localhost:3000NEXT_PUBLIC_SITE_URL=https://yourdomain.comAnalytics
Vibestacks uses PostHog for product analytics. PostHog is privacy-friendly and offers a generous free tier.
| Variable | Required | Description |
|---|---|---|
NEXT_PUBLIC_POSTHOG_KEY | ❌ | Your PostHog project API key |
NEXT_PUBLIC_POSTHOG_HOST | ❌ | PostHog ingestion endpoint |
NEXT_PUBLIC_POSTHOG_KEY=phc_your_project_key
NEXT_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.comNEXT_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.comNEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.comTo get your API key:
- Create a free account at posthog.com
- Go to Project Settings → Project API Key
- Copy the key (starts with
phc_)
Optional for local development
Analytics are optional during development. The app will run without these variables configured.
Vibestacks uses Resend for transactional emails (welcome emails, password resets, notifications, etc.).
| Variable | Required | Description |
|---|---|---|
RESEND_API_KEY | ❌ | Your Resend API key |
RESEND_API_KEY=re_your_api_keyTo get your API key:
- Create an account at resend.com
- Go to API Keys → Create API Key
- Copy the key (starts with
re_)
Domain verification
For production, you'll need to verify your sending domain in Resend. During development, you can send to your own email address without verification.
Error Tracking
Vibestacks uses Sentry for error tracking and performance monitoring.
| Variable | Required | Description |
|---|---|---|
SENTRY_AUTH_TOKEN | ❌ | Sentry authentication token for source maps |
SENTRY_AUTH_TOKEN=sntrys_your_token_hereTo get your auth token:
- Create an account at sentry.io
- Go to Settings → Auth Tokens
- Create a new token with
project:releasesandorg:readscopes
Optional for local development
Sentry is optional during development. Errors will be logged to the console instead.
Development Settings
| Variable | Required | Description |
|---|---|---|
NODE_ENV | ❌ | Environment mode (development or production) |
NODE_ENV=developmentThis is typically set automatically by Next.js based on the command you run (pnpm dev vs pnpm build).
Complete Example
Here's a complete .env.local file with all variables:
# ─────────────────────────────────────────────────────────────
# Core (Required)
# ─────────────────────────────────────────────────────────────
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/vibestacks"
BETTER_AUTH_SECRET="your-generated-secret-here"
NEXT_PUBLIC_SITE_URL=http://localhost:3000
# ─────────────────────────────────────────────────────────────
# Analytics (Optional)
# ─────────────────────────────────────────────────────────────
NEXT_PUBLIC_POSTHOG_KEY=phc_your_project_key
NEXT_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com
# ─────────────────────────────────────────────────────────────
# Email (Optional)
# ─────────────────────────────────────────────────────────────
RESEND_API_KEY=re_your_api_key
# ─────────────────────────────────────────────────────────────
# Error Tracking (Optional)
# ─────────────────────────────────────────────────────────────
SENTRY_AUTH_TOKEN=sntrys_your_token_here
# ─────────────────────────────────────────────────────────────
# Development
# ─────────────────────────────────────────────────────────────
NODE_ENV=developmentEnvironment-Specific Configuration
For local development, you only need the core variables:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/vibestacks"
BETTER_AUTH_SECRET="any-string-for-local-dev"
NEXT_PUBLIC_SITE_URL=http://localhost:3000
NODE_ENV=developmentAnalytics, email, and error tracking are optional locally.
For production deployments, configure all variables in your hosting provider's dashboard (Vercel, Railway, etc.):
- Use your production database URL
- Generate a strong
BETTER_AUTH_SECRET - Set
NEXT_PUBLIC_SITE_URLto your domain - Configure analytics, email, and error tracking
Vercel
In Vercel, go to Project Settings → Environment Variables to add these values.
Troubleshooting
"Missing environment variable" error
T3 Env validates all required variables at build time. If you see this error:
- Check that
.env.localexists in your project root - Verify the variable name matches exactly (case-sensitive)
- Restart the dev server after changing environment variables
Changes not taking effect
Next.js caches environment variables. After making changes:
# Restart the development server
pnpm devFor NEXT_PUBLIC_* variables, you may need to clear the Next.js cache:
rm -rf .next
pnpm devNext Steps
Once your environment is configured:
- Database Setup - Push your schema and explore Drizzle Studio
- IDE Setup - Optimize your editor for Vibestacks
Installation & Local Development
Step-by-step guide to installing Vibestacks locally. Learn how to set up Docker, install dependencies with pnpm, and launch your development server in minutes.
Drizzle ORM & PostgreSQL
Connect and manage your PostgreSQL database using Drizzle ORM. comprehensive guide to local Docker setup, Neon/Supabase integration, and handling schema migrations.