Overview
The starter kit requires several environment variables to connect to Supabase, Dodo Payments, and enable authentication. All variables must be set in your.env.local file for local development and in your deployment platform (Vercel) for production.
Quick Setup
Create a.env.local file in your project root:
Environment Variables Reference
Supabase Configuration
Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL
Required: YesType: Public
Example:
https://abcdefghijklmno.supabase.coYour Supabase project URL.How to get it:- Go to Supabase Dashboard
- Select your project
- Go to Settings → API
- Copy the Project URL
NEXT_PUBLIC_SUPABASE_ANON_KEY
Required: YesType: Public
Example:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...The anonymous/public key for client-side Supabase operations.How to get it:- Go to Supabase Dashboard
- Select your project
- Go to Settings → API
- Copy the anon public key
SUPABASE_SERVICE_ROLE_KEY
Required: YesType: Secret
Example:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...The service role key with full database access. Used by the webhook function to write subscription and payment data.How to get it:- Go to Supabase Dashboard
- Select your project
- Go to Settings → API
- Copy the service_role key (click “Reveal” first)
- Supabase Edge Function (webhook handler)
- Server-side operations requiring elevated permissions
Database Configuration
Database Configuration
DATABASE_URL
Required: YesType: Secret
Example:
postgresql://postgres:[email protected]:5432/postgresPostgreSQL connection string for Drizzle ORM migrations and schema management.How to get it:- Go to Supabase Dashboard
- Select your project
- Go to Settings → Database
- Copy the Connection String under “Connection pooling”
- Replace
[YOUR-PASSWORD]with your actual database password
If your password contains special characters, make sure to URL-encode them. For example,
@ becomes %40.- Running database migrations:
bun run db:push - Schema generation:
bun run db:generate - Database studio:
bun run db:studio
Dodo Payments Configuration
Dodo Payments Configuration
DODO_PAYMENTS_API_KEY
Required: YesType: Secret
Example:
dodo_test_abc123... or dodo_live_xyz789...Your Dodo Payments API key for creating checkout sessions and managing subscriptions.How to get it:- Go to Dodo Payments Dashboard
- Navigate to Settings → API Keys
- Copy your Test Mode key for development or Live Mode key for production
- Creating checkout sessions
- Managing customer subscriptions
- Retrieving product information
- Processing payment operations
DODO_WEBHOOK_SECRET
Required: YesType: Secret
Example:
whsec_abc123...Secret key for verifying webhook signatures from Dodo Payments.How to get it:- Go to Dodo Payments Dashboard
- Navigate to Settings → Webhooks
- Add a new webhook endpoint or copy the secret from an existing one
- Copy the Signing Secret
- Supabase Edge Function webhook handler
- Webhook signature verification
DODO_PAYMENTS_ENVIRONMENT
Required: YesType: Configuration
Allowed Values:
test_mode or live_modeExample:
test_modeDetermines whether to use Dodo Payments in test or live mode.Values:test_mode: Use test API keys, no real chargeslive_mode: Use live API keys, real charges processed
Setting Up Environment Variables
Local Development
-
Copy the example file:
-
Fill in all required values:
-
Restart your development server:
Vercel Deployment
Via Dashboard
- Go to your Vercel project
- Navigate to Settings → Environment Variables
- Add each variable with appropriate scope:
- Production: For production deployments
- Preview: For pull request previews
- Development: For local development with
vercel dev
Via CLI
Supabase Edge Function
The webhook function also needs environment variables set in Supabase:- Go to Supabase Dashboard
- Select your project
- Navigate to Edge Functions → dodo-webhook → Settings
- Add these environment variables:
SUPABASE_URL: Same asNEXT_PUBLIC_SUPABASE_URLSUPABASE_SERVICE_ROLE_KEY: Your service role keyDODO_WEBHOOK_SECRET: Your webhook secret
When deploying the webhook function, these variables are automatically available from your Supabase project if they’re set in the Supabase dashboard.
Security Best Practices
Never Commit Secrets
Ensure.env.local is in your .gitignore:
Rotate Keys Regularly
Periodically rotate sensitive keys:- Dodo Payments API keys
- Webhook secrets
- Service role keys
Use Different Keys Per Environment
Maintain separate API keys for:- Local development (test mode)
- Staging/preview (test mode)
- Production (live mode)
Restrict Access
Limit who has access to:- Production environment variables
- Live mode API keys
- Service role keys
Validation
To verify all environment variables are correctly set, the application performs validation on startup. Check for missing variables: The app will fail to start if required variables are missing, with clear error messages indicating which variables need to be set. Test database connection:DATABASE_URL is valid.
Test Supabase connection:
Navigate to /auth/login and attempt to sign in. If authentication works, your Supabase configuration is correct.
Test Dodo Payments:
Create a test checkout session. If it redirects to Dodo Payments, your API key is valid.
Troubleshooting
”Missing environment variable” Error
Cause: Required variable is not set or misspelled. Solution:- Check
.env.localfile exists - Verify variable names match exactly (case-sensitive)
- Restart development server after changes
Authentication Fails
Cause: Incorrect Supabase URL or keys. Solution:- Verify
NEXT_PUBLIC_SUPABASE_URLis correct - Ensure
NEXT_PUBLIC_SUPABASE_ANON_KEYis the anon key, not service role - Check for trailing slashes or spaces in URL
Database Connection Error
Cause: InvalidDATABASE_URL format or credentials.
Solution:
- Verify password is URL-encoded
- Check project reference ID is correct
- Ensure database is accessible (not paused)
- Confirm connection string uses port 5432
Webhook Signature Verification Fails
Cause: IncorrectDODO_WEBHOOK_SECRET.
Solution:
- Verify secret matches Dodo Payments dashboard
- Ensure no extra spaces or newlines
- Check webhook endpoint is using the correct secret
- Confirm secret is set in Supabase Edge Function environment
Payment API Errors
Cause: Invalid or missingDODO_PAYMENTS_API_KEY.
Solution:
- Confirm API key starts with
dodo_test_ordodo_live_ - Verify key matches the
DODO_PAYMENTS_ENVIRONMENTsetting - Check key hasn’t been revoked in dashboard
- Ensure no extra characters or spaces
Reference Summary
| Variable | Required | Type | Used By |
|---|---|---|---|
NEXT_PUBLIC_SUPABASE_URL | Yes | Public | Client, Server |
NEXT_PUBLIC_SUPABASE_ANON_KEY | Yes | Public | Client, Server |
SUPABASE_SERVICE_ROLE_KEY | Yes | Secret | Server, Webhook |
DATABASE_URL | Yes | Secret | Drizzle ORM |
DODO_PAYMENTS_API_KEY | Yes | Secret | Server |
DODO_WEBHOOK_SECRET | Yes | Secret | Webhook |
DODO_PAYMENTS_ENVIRONMENT | Yes | Config | Server, Webhook |
Public variables are safe to expose in client-side code. Secret variables must never be exposed to the client.
