Overview
Ticket Hub uses@t3-oss/env-nextjs for type-safe environment variable validation. This ensures that all required variables are set before the app starts, preventing runtime errors.
Environment Schema
The environment configuration is defined insrc/env.ts:
src/env.ts
The schema automatically validates all environment variables at build time. Missing or invalid variables will cause the build to fail with clear error messages.
Required Environment Variables
Clerk Authentication
Get Clerk API Keys
- Go to clerk.com and sign in
- Select your application
- Navigate to API Keys
- Copy the keys
Client-side publishable key from Clerk dashboard.
- Prefix:
pk_test_(test) orpk_live_(production) - Safe to expose in client-side code
- Used to initialize Clerk in the browser
Server-side secret key from Clerk dashboard.
- Prefix:
sk_test_(test) orsk_live_(production) - Keep this secure - never expose in client code
- Used for server-side API calls
Signing secret for verifying Clerk webhook requests.
- Prefix:
whsec_ - Found in Clerk dashboard → Webhooks → Your endpoint
- Ensures webhooks are authentic
Path to your sign-in page. Must match Clerk dashboard configuration.
Path to your sign-up page. Must match Clerk dashboard configuration.
Convex Backend
Initialize Convex
Run Convex development mode:This will:
- Create a Convex project (first time)
- Deploy your schema and functions
- Output your deployment URL
Get deployment credentials
For production deployments:
- Go to convex.dev
- Select your project
- Go to Settings → Deploy Keys
- Create a new deploy key
Your Convex deployment URL.
- Format:
https://[deployment-name].convex.cloud - Automatically generated when you run
npx convex dev - Different for each environment (dev, staging, prod)
Your Convex deployment identifier.
- Found in Convex dashboard → Settings
- Used for production deployments
- Format:
prod:your-deployment-name
Deploy key for automated deployments.
- Created in Convex dashboard → Settings → Deploy Keys
- Required for CI/CD pipelines
- Keep this secret
Stripe Payments
Get Stripe API Keys
- Go to stripe.com and sign in
- Navigate to Developers → API Keys
- Copy your Secret Key
Set up Stripe webhooks
- Go to Developers → Webhooks
- Click Add endpoint
- Enter URL:
https://your-app.vercel.app/api/webhooks/stripe - Select events:
payment_intent.succeededpayment_intent.payment_failedcharge.refunded
- Copy the Signing Secret
Your Stripe secret API key.
- Prefix:
sk_test_(test mode) orsk_live_(live mode) - Found in Stripe dashboard → API Keys
- Used for creating payment intents and processing charges
- Never expose this in client-side code
Signing secret for Stripe webhook verification.
- Prefix:
whsec_ - Found in Stripe dashboard → Webhooks → Your endpoint
- Ensures webhook events are genuine
Application Configuration
The public URL of your application.
- Development:
http://localhost:3000 - Production:
https://your-app.vercel.app - Used for redirects and callback URLs
Your Vercel production URL.
- Format:
your-project.vercel.app(withouthttps://) - Automatically set by Vercel in production
- For local development, use your expected production URL
Application environment.
- Values:
development,test,production - Automatically set by Next.js
- Optional to set manually
Port for local development server.
- Default:
3000 - Optional - only needed if you want a different port
Complete .env.local Example
.env.local
Environment-Specific Configuration
Development
.env.local
Production
.env.production
Validation and Type Safety
Accessing Environment Variables
Import fromsrc/env.ts for type-safe access:
Skipping Validation
For Docker builds or specific CI scenarios:Troubleshooting
Build fails with 'Invalid environment variables'
Build fails with 'Invalid environment variables'
Check that all required variables are set in your
.env.local file. The error message will tell you exactly which variables are missing or invalid.'NEXT_PUBLIC_* variables not available in browser'
'NEXT_PUBLIC_* variables not available in browser'
Make sure:
- Variables start with
NEXT_PUBLIC_prefix - You’ve restarted the dev server after adding them
- They’re in
.env.local, not just exported in your shell
Webhook secrets not working
Webhook secrets not working
Verify:
- The webhook URL is correct and publicly accessible
- The signing secret matches exactly (no extra spaces)
- You’re using the correct environment (test vs. live)
Convex URL not found
Convex URL not found
Run
npx convex dev to:- Generate the Convex deployment
- Get the correct
NEXT_PUBLIC_CONVEX_URL - Ensure Convex is properly initialized
Next Steps
Quickstart
Get the app running with these environment variables
Authentication
Deep dive into Clerk authentication setup
Stripe Integration
Set up payment processing with Stripe
API Reference
Explore the Convex API functions