Overview
The application requires environment variables for:- Clerk - User authentication and management
- Liveblocks - Real-time collaboration features
- Sentry - Error monitoring (optional)
Environment variables prefixed with
NEXT_PUBLIC_ are exposed to the browser. Keep secret keys private by NOT using this prefix.Required Environment Variables
Clerk Authentication
Clerk handles user authentication, session management, and user profiles.How to Get Clerk Keys
Create Clerk Application
- Go to clerk.com and sign up
- Create a new application
- Choose your authentication methods (Email, Google, GitHub, etc.)
Get API Keys
- Navigate to API Keys in the Clerk Dashboard
- Copy your Publishable Key →
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY - Copy your Secret Key →
CLERK_SECRET_KEY
Liveblocks Collaboration
Liveblocks powers the real-time collaboration features including presence, comments, and document sync.How to Get Liveblocks Keys
Create Liveblocks Project
- Go to liveblocks.io and sign up
- Create a new project
- Choose the appropriate plan (Free tier available)
The secret key is used server-side in
lib/liveblocks.ts:4 to authenticate users via the /api/liveblocks-auth endpoint.Optional Environment Variables
Sentry Error Monitoring
Sentry provides error tracking and performance monitoring for production applications.How to Get Sentry Configuration
Create Sentry Project
- Go to sentry.io and sign up
- Create a new project
- Select Next.js as the platform
Get DSN
- Go to Settings → Projects → Your Project
- Click on Client Keys (DSN)
- Copy the DSN →
SENTRY_DSN
Get Organization & Project Names
SENTRY_ORG: Found in Settings → General Settings → Organization SlugSENTRY_PROJECT: Your project name (slug)
The application is pre-configured with Sentry (
sentry.server.config.ts:8). The DSN is hardcoded, so you may want to replace it with your own or use the environment variable pattern.Local Development Setup
Creating .env.local File
Create a.env.local file in the root of your project:
Running Locally
After setting up your environment variables:http://localhost:3000.
Production Setup
Vercel Deployment
For Vercel deployments:- Go to your project settings in Vercel
- Navigate to Environment Variables
- Add each variable with the appropriate value
- Select the environment (Production, Preview, Development)
Other Platforms
For other hosting platforms:- Netlify: Use the Environment Variables section in Site Settings
- Railway: Use the Variables tab in your project
- Docker: Use a
.envfile or pass viadocker run -e
Environment-Specific Configuration
Development vs Production
The application behaves differently based on environment: Development (npm run dev):
- Uses test/development API keys from Clerk
- Sentry debug mode can be enabled (
sentry.server.config.ts:14) - Hot module reloading enabled
- Detailed error messages
npm run build && npm start):
- Uses production API keys
- Source maps uploaded to Sentry
- Optimized builds with code splitting
- Error boundaries active
Verifying Configuration
Check Clerk Integration
- Start your development server
- Navigate to
http://localhost:3000 - You should see Clerk’s authentication UI
- Try signing in/up to verify the keys work
Check Liveblocks Integration
- Sign in to the application
- Create a new document
- Open the browser console and check for Liveblocks connection messages
- No authentication errors should appear
Check Sentry Integration
- Trigger an error in development
- Check the Sentry dashboard for the error event
- Verify source maps are working (you see original code, not minified)
Troubleshooting
”Unauthorized” Errors
- Verify
CLERK_SECRET_KEYis set correctly - Check that the key matches your environment (test vs production)
- Ensure the key hasn’t expired or been rotated
Liveblocks Connection Failures
- Confirm
LIVEBLOCKS_SECRET_KEYis set (required inlib/liveblocks.ts:4) - Verify the public key matches the secret key’s project
- Check Liveblocks dashboard for API usage limits
Environment Variables Not Loading
- Restart your development server after adding new variables
- Verify
.env.localis in the project root directory - Check for typos in variable names
- Ensure
NEXT_PUBLIC_prefix for client-side variables
Next.js only loads environment variables on server start. You must restart
npm run dev after changing .env.local.Security Best Practices
- Never commit secrets: Add
.env.localto.gitignore - Rotate keys regularly: Update API keys every 3-6 months
- Use separate keys: Different keys for development and production
- Limit key permissions: Use the minimum required scopes
- Monitor usage: Check dashboards for unusual activity