Vibestacks LogoVibestacks
Getting Started

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.local

Open .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

VariableRequiredDescription
DATABASE_URLPostgreSQL 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

VariableRequiredDescription
BETTER_AUTH_SECRETSecret key for signing session cookies

A secure random string used by Better Auth to sign and verify session cookies. Generate one with:

Generate a secure secret
openssl rand -base64 32

Keep this secret

Never share or expose this value. If compromised, rotate it immediately - this will invalidate all existing user sessions.

Application URL

VariableRequiredDescription
NEXT_PUBLIC_SITE_URLThe base URL of your application

The public URL where your app is accessible. This is used for generating links, OAuth callbacks, and metadata.

Local development
NEXT_PUBLIC_SITE_URL=http://localhost:3000
Production
NEXT_PUBLIC_SITE_URL=https://yourdomain.com

Analytics

Vibestacks uses PostHog for product analytics. PostHog is privacy-friendly and offers a generous free tier.

VariableRequiredDescription
NEXT_PUBLIC_POSTHOG_KEYYour PostHog project API key
NEXT_PUBLIC_POSTHOG_HOSTPostHog ingestion endpoint
NEXT_PUBLIC_POSTHOG_KEY=phc_your_project_key
NEXT_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com
NEXT_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com
NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com

To get your API key:

  1. Create a free account at posthog.com
  2. Go to Project SettingsProject API Key
  3. Copy the key (starts with phc_)

Optional for local development

Analytics are optional during development. The app will run without these variables configured.


Email

Vibestacks uses Resend for transactional emails (welcome emails, password resets, notifications, etc.).

VariableRequiredDescription
RESEND_API_KEYYour Resend API key
RESEND_API_KEY=re_your_api_key

To get your API key:

  1. Create an account at resend.com
  2. Go to API KeysCreate API Key
  3. 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.

VariableRequiredDescription
SENTRY_AUTH_TOKENSentry authentication token for source maps
SENTRY_AUTH_TOKEN=sntrys_your_token_here

To get your auth token:

  1. Create an account at sentry.io
  2. Go to SettingsAuth Tokens
  3. Create a new token with project:releases and org:read scopes

Optional for local development

Sentry is optional during development. Errors will be logged to the console instead.


Development Settings

VariableRequiredDescription
NODE_ENVEnvironment mode (development or production)
NODE_ENV=development

This 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:

.env.local
# ─────────────────────────────────────────────────────────────
# 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=development

Environment-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=development

Analytics, 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_URL to your domain
  • Configure analytics, email, and error tracking

Vercel

In Vercel, go to Project SettingsEnvironment Variables to add these values.


Troubleshooting

"Missing environment variable" error

T3 Env validates all required variables at build time. If you see this error:

  1. Check that .env.local exists in your project root
  2. Verify the variable name matches exactly (case-sensitive)
  3. 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 dev

For NEXT_PUBLIC_* variables, you may need to clear the Next.js cache:

rm -rf .next
pnpm dev

Next Steps

Once your environment is configured: