We use tracking cookies to understand how you use the product and help us improve it. For more information on how we store cookies, read our  privacy policy.

Environment Variables

Configure environment variables for Plainform integrations

Environment Variables

Plainform uses environment variables to configure integrations securely. All variables are validated at runtime using @t3-oss/env-nextjs and Zod schemas.

If any required variable is missing or invalid, the application won't start. This prevents runtime errors and security issues.

Quick Setup

Create .env file

Create a .env file in the project root:

Create .env file
touch .env

Copy template

Use the template below and fill in your values from each service provider.

Validation

The app automatically validates all variables on startup via env.ts.

Complete .env Template

.env
# Application
SITE_URL="http://localhost:3000"
NEXT_PUBLIC_SITE_URL="http://localhost:3000"

# Clerk (Authentication)
NEXT_PUBLIC_CLERK_SIGN_IN_URL="/sign-in"
NEXT_PUBLIC_CLERK_SIGN_UP_URL="/sign-up"
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="pk_test_xxxx"
CLERK_SECRET_KEY="sk_test_xxxx"

# Stripe (Payments)
STRIPE_SECRET_KEY="sk_test_xxxx"
STRIPE_PUBLISHABLE_KEY="pk_test_xxxx"
STRIPE_WEBHOOK_SECRET="whsec_xxxx"

# Supabase (Database)
DATABASE_URL="postgresql://user:password@host:6543/postgres?pgbouncer=true"
DIRECT_URL="postgresql://user:password@host:5432/postgres"

# AWS S3 (Storage)
AWS_ACCESS_KEY_ID="AKIAXXXXXXXXXXXX"
AWS_SECRET_ACCESS_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
AWS_S3_ENDPOINT="https://your-bucket.s3.region.amazonaws.com"
AWS_S3_REGION="us-east-1"
AWS_S3_BUCKET="your-bucket-name"

# Resend (Emails)
RESEND_API_KEY="re_xxxx"

# Mailchimp (Newsletter)
MAILCHIMP_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us19"
MAILCHIMP_API_SERVER="us6"
MAILCHIMP_AUDIENCE_ID="xxxxxxxxxx"

# PostHog (Analytics)
NEXT_PUBLIC_POSTHOG_KEY="phc_xxxx"
NEXT_PUBLIC_POSTHOG_HOST="https://us.i.posthog.com"

Variable Reference

Application

Env VariableTypeDefault
SITE_URL
string
http://localhost:3000
NEXT_PUBLIC_SITE_URL
string
http://localhost:3000

Use http://localhost:3000 in development and your production domain in production (e.g., https://yourdomain.com).

Clerk (Authentication)

Env VariableTypeDefault
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
string
pk_test_xxxx
CLERK_SECRET_KEY
string
sk_test_xxxx
NEXT_PUBLIC_CLERK_SIGN_IN_URL
string
/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL
string
/sign-up

Where to find:

  1. Go to Clerk Dashboard
  2. Select your application
  3. Navigate to API Keys section
  4. Copy the keys for your environment

Stripe (Payments)

Env VariableTypeDefault
STRIPE_SECRET_KEY
string
sk_test_xxxx
STRIPE_PUBLISHABLE_KEY
string
pk_test_xxxx
STRIPE_WEBHOOK_SECRET
string
whsec_xxxx

Where to find:

  1. Go to Stripe Dashboard
  2. Navigate to Developers → API keys
  3. Copy Secret key and Publishable key
  4. For webhook secret: Developers → Webhooks → Add endpoint → Copy signing secret

Use test keys (sk_test_, pk_test_) in development. Switch to live keys in production.

Supabase (Database)

Env VariableTypeDefault
DATABASE_URL
string
postgresql://user:password@host:6543/postgres?pgbouncer=true
DIRECT_URL
string
postgresql://user:password@host:5432/postgres

Where to find:

  1. Go to Supabase Dashboard
  2. Select your project
  3. Navigate to Settings → Database
  4. Copy "Connection string" for DATABASE_URL (Transaction mode)
  5. Copy "Connection string" for DIRECT_URL (Session mode)

DATABASE_URL uses port 6543 with pgbouncer for connection pooling. DIRECT_URL uses port 5432 for direct connections (required for Prisma migrations).

AWS S3 (Storage)

Env VariableTypeDefault
AWS_ACCESS_KEY_ID
string
-
AWS_SECRET_ACCESS_KEY
string
-
AWS_S3_ENDPOINT
string
https://your-bucket.s3.region.amazonaws.com
AWS_S3_REGION
string
-
AWS_S3_BUCKET
string
-

Where to find:

  1. Go to AWS Console
  2. Navigate to IAM → Users → Create user
  3. Attach policy: AmazonS3FullAccess
  4. Create access key → Copy Access Key ID and Secret Access Key
  5. Navigate to S3 → Create bucket → Copy bucket name and region

Resend (Emails)

Env VariableTypeDefault
RESEND_API_KEY
string
re_xxxx

Where to find:

  1. Go to Resend Dashboard
  2. Navigate to API Keys
  3. Create API key → Copy the key

Mailchimp (Newsletter)

Env VariableTypeDefault
MAILCHIMP_API_KEY
string
-
MAILCHIMP_API_SERVER
string
-
MAILCHIMP_AUDIENCE_ID
string
-

Where to find:

  1. Go to Mailchimp Dashboard
  2. Navigate to Account → Extras → API keys
  3. Create API key → Copy the key (note the server prefix like us6)
  4. Navigate to Audience → Settings → Audience name and defaults → Copy Audience ID

PostHog (Analytics)

Env VariableTypeDefault
NEXT_PUBLIC_POSTHOG_KEY
string
phc_xxxx
NEXT_PUBLIC_POSTHOG_HOST
string
https://us.i.posthog.com

Where to find:

  1. Go to PostHog Dashboard
  2. Navigate to Project Settings
  3. Copy Project API Key
  4. Copy Host URL (use EU endpoint for GDPR compliance)

Validation Schema

All environment variables are validated in env.ts using Zod:

env.ts
// From env.ts
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
  server: {
    STRIPE_SECRET_KEY: z.string().min(5),
    DATABASE_URL: z.string().min(5),
    // ... other server variables
  },
  client: {
    NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(5),
    NEXT_PUBLIC_POSTHOG_KEY: z.string().min(5),
    // ... other client variables
  },
  experimental__runtimeEnv: {
    NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL,
    // ... other client variables
  },
});

Local vs Production

Development (.env file):

  • Use test/sandbox keys for all services
  • Use http://localhost:3000 for URLs
  • Stripe: sk_test_ and pk_test_ keys
  • Clerk: pk_test_ and sk_test_ keys
  • Database: Development database connection

Production (Vercel/hosting platform):

  • Use live/production keys
  • Use your production domain for URLs
  • Stripe: sk_live_ and pk_live_ keys
  • Clerk: pk_live_ and sk_live_ keys
  • Database: Production database connection
  • Set variables in hosting platform dashboard (e.g., Vercel → Settings → Environment Variables)

Security Best Practices

  1. Never commit .env files - Already in .gitignore
  2. Use different keys per environment - Test keys in dev, live keys in production
  3. Rotate keys regularly - Especially after team member changes
  4. Limit key permissions - Use least-privilege principle (e.g., read-only keys where possible)
  5. Validate on startup - The env.ts schema prevents missing/invalid variables

Never expose server-side variables to the client. Only variables prefixed with NEXT_PUBLIC_ are accessible in the browser.

Troubleshooting

Next Steps

How is this guide ?

Last updated on