Environment Variables
Managing environment variables in ShipKit
Environment Variables
ShipKit uses T3 Env for type-safe environment variable validation, ensuring runtime safety and excellent TypeScript integration.
Quick Setup
- Copy the example environment file:
cp .env.example .env.local
- Generate required secrets:
# Generate AUTH_SECRET
openssl rand -base64 32
Required Variables
Core Authentication
# Base URL for authentication
# In production, this will be automatically set to VERCEL_URL
AUTH_URL="http://localhost:3000"
# JWT secret for session management
# Generate with: openssl rand -base64 32
AUTH_SECRET=""
OAuth Providers (Optional)
# GitHub OAuth
AUTH_GITHUB_ID=""
AUTH_GITHUB_SECRET=""
# Discord OAuth
AUTH_DISCORD_ID=""
AUTH_DISCORD_SECRET=""
# Google OAuth
AUTH_GOOGLE_ID=""
AUTH_GOOGLE_SECRET=""
Database
# PostgreSQL connection string
DATABASE_URL="postgresql://postgres:password@localhost:5432/shipkit"
# Database prefix (defaults to "db")
DB_PREFIX="db"
External Services (Optional)
GitHub Integration
# GitHub access token for repo operations
GITHUB_ACCESS_TOKEN=""
Google Services
# Google service account credentials
GOOGLE_CLIENT_EMAIL=""
GOOGLE_PRIVATE_KEY=""
AI Services
# OpenAI API key
OPENAI_API_KEY=""
# Anthropic API key
ANTHROPIC_API_KEY=""
Payments
# LemonSqueezy credentials
LEMONSQUEEZY_API_KEY=""
LEMONSQUEEZY_STORE_ID=""
Node Environment
# Node environment (defaults to "development")
# Values: development, test, production
NODE_ENV="development"
Type Safety
Environment variables are validated using T3 Env and Zod schemas:
// src/env.ts
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
export const env = createEnv({
server: {
DATABASE_URL: z.string().url().optional(),
DB_PREFIX: z.string().default("db"),
NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
// Auth
AUTH_SECRET: z.string().optional(),
AUTH_URL: z.preprocess(
(str) => process.env.VERCEL_URL ?? str,
process.env.VERCEL ? z.string().optional() : z.string().url().optional(),
),
AUTH_DISCORD_ID: z.string().optional(),
AUTH_DISCORD_SECRET: z.string().optional(),
AUTH_GITHUB_ID: z.string().optional(),
AUTH_GITHUB_SECRET: z.string().optional(),
AUTH_GOOGLE_ID: z.string().optional(),
AUTH_GOOGLE_SECRET: z.string().optional(),
// GitHub
GITHUB_ACCESS_TOKEN: z.string().optional(),
// Google
GOOGLE_CLIENT_EMAIL: z.string().optional(),
GOOGLE_PRIVATE_KEY: z.string().optional(),
// AI Services
OPENAI_API_KEY: z.string().optional(),
ANTHROPIC_API_KEY: z.string().optional(),
// Payments
LEMONSQUEEZY_API_KEY: z.string().optional(),
LEMONSQUEEZY_STORE_ID: z.string().optional(),
},
});
Environment Management
Local Development
- Copy the example environment file:
cp .env.example .env.local
- Update variables in
.env.local
Production (Vercel)
- Add variables through the Vercel dashboard or CLI:
vercel env add MY_VAR
- After adding variables, redeploy your application:
vercel --prod