Overview
This application requires specific environment variables to function correctly. These variables configure Supabase integration and secure the cron endpoint.Required Environment Variables
Supabase Configuration
The application uses Supabase for database operations. Two public environment variables are required:NEXT_PUBLIC_SUPABASE_URL
- Purpose: The URL of your Supabase project
- Format:
https://your-project-id.supabase.co - Used in:
src/utils/supabase/server.ts:8 - Scope: Public (prefixed with
NEXT_PUBLIC_)
Variables prefixed with
NEXT_PUBLIC_ are exposed to the browser. Only use this prefix for non-sensitive values like the Supabase URL.NEXT_PUBLIC_SUPABASE_ANON_KEY
- Purpose: The anonymous/public API key for Supabase client authentication
- Format: Long base64-encoded string (starts with
eyJ) - Used in:
src/utils/supabase/server.ts:9 - Scope: Public (prefixed with
NEXT_PUBLIC_)
Cron Job Security
CRON_SECRET
- Purpose: Authenticates requests to the
/api/cronendpoint - Format: Any secure random string (recommended: 32+ characters)
- Used in:
src/app/api/cron/route.ts:6 - Scope: Server-only (no
NEXT_PUBLIC_prefix)
This secret is used by Vercel’s cron job system to authenticate requests. Generate a strong random string for this value.
Setting Up Environment Variables
Local Development
Create .env.local file
In your project root, create a
.env.local file:The
.env.local file is gitignored by default in Next.js projects. Never commit this file to version control.Get Supabase credentials
Retrieve your Supabase credentials:
- Log in to Supabase Dashboard
- Select your project
- Navigate to Settings > API
- Copy the “Project URL” (for
NEXT_PUBLIC_SUPABASE_URL) - Copy the “anon public” key (for
NEXT_PUBLIC_SUPABASE_ANON_KEY)
Production (Vercel)
Navigate to project settings
- Open your project in Vercel dashboard
- Go to Settings > Environment Variables
Add each variable
For each environment variable:
- Enter the variable name (e.g.,
NEXT_PUBLIC_SUPABASE_URL) - Enter the value
- Select the environments: Production, Preview, Development
- Click “Save”
How Environment Variables Are Used
Supabase Server Client
The Supabase client is created insrc/utils/supabase/server.ts:
src/utils/supabase/server.ts
Server Actions (Message Submission)
The application includes a server action for submitting anonymous messages insrc/app/actions.ts:
src/app/actions.ts
The
/talk page that uses this server action is currently disabled in the live site, but the functionality remains in the codebase.Cron Endpoint Authentication
The cron endpoint usesCRON_SECRET to verify requests:
src/app/api/cron/route.ts
Authorization: Bearer {CRON_SECRET} header when triggering scheduled cron jobs.
Verification
Verify Local Setup
- Start the development server:
npm run dev - Check for any missing environment variable errors in the console
- Test Supabase connectivity by accessing features that use the database
Verify Production Setup
- Check Vercel deployment logs for environment variable errors
- Visit your deployed site and test database functionality
- Monitor function logs for any runtime errors related to missing variables
Security Best Practices
- Use strong, randomly generated values for
CRON_SECRET - Rotate secrets periodically, especially if exposed
- Enable Supabase Row Level Security (RLS) policies to protect data
- Review Supabase logs regularly for unauthorized access attempts
- Use different Supabase projects for development and production
Troubleshooting
Error: “Missing environment variable”
- Verify the variable name matches exactly (case-sensitive)
- Ensure
.env.localexists in project root (for local development) - Restart the development server after adding variables
- Check Vercel dashboard for production variables
Supabase Connection Fails
- Verify
NEXT_PUBLIC_SUPABASE_URLformat is correct - Check
NEXT_PUBLIC_SUPABASE_ANON_KEYis the complete key - Ensure Supabase project is active and not paused
- Verify network connectivity to Supabase servers
Cron Job Returns 401 Unauthorized
- Verify
CRON_SECRETis set in Vercel environment variables - Ensure the secret matches between Vercel settings and your code
- Check Vercel cron job configuration in dashboard