Setup Methods
You can configure environment variables in two ways:- Automated Setup (Recommended): Run the interactive setup script
- Manual Setup: Create and configure the
.envfile yourself
Automated Setup
The easiest way to configure your environment is to use the automated setup script:- Check for Stripe CLI installation and authentication
- Set up your PostgreSQL database (local or remote)
- Retrieve your Stripe API keys
- Create a webhook secret automatically
- Generate a secure
AUTH_SECRET - Write all variables to
.env
The setup script requires the Stripe CLI to be installed. If not found, it will provide installation instructions.
Manual Setup
If you prefer to configure environment variables manually, create a.env file in the root of your project with the following variables:
Required Environment Variables
PostgreSQL database connection stringFormat:
postgresql://[user]:[password]@[host]:[port]/[database]Example: postgresql://postgres:postgres@localhost:54322/postgresWhere to get it:- Local Development: Use Docker Compose (see Database Setup)
- Production: Get from your hosting provider (Vercel Postgres, Neon, Supabase, etc.)
Your Stripe secret API key for processing paymentsFormat:
sk_test_... (test mode) or sk_live_... (production)Where to get it:- Go to Stripe Dashboard > API Keys
- Copy the “Secret key” (starts with
sk_test_for test mode) - For production, switch to live mode and use your live secret key
Stripe webhook signing secret for verifying webhook eventsFormat: This command will output your webhook secret. Copy the value that starts with
whsec_...Where to get it:Development:whsec_.Production:- Go to Stripe Dashboard > Webhooks
- Click “Add endpoint”
- Enter your webhook URL:
https://yourdomain.com/api/stripe/webhook - Select events to listen to (at minimum:
customer.subscription.updated,customer.subscription.deleted) - Copy the “Signing secret” from the webhook details page
The webhook secret ensures that webhook events are actually coming from Stripe and haven’t been tampered with.
The base URL of your applicationDevelopment:
http://localhost:3000Production: https://yourdomain.comThis is used for:- Stripe checkout success/cancel redirects
- Billing portal return URLs
- Email links and callbacks
Secret key for signing and encrypting authentication tokensHow to generate:Or use OpenSSL:
Example Configuration
Your.env file should look like this:
.env
File Location
From the source code comments in.env.example:
Security Best Practices
Additional Security Tips
- Rotate secrets regularly: Change
AUTH_SECRETand regenerate API keys periodically - Use test mode in development: Always use Stripe test keys (
sk_test_) during development - Limit API key permissions: Use restricted API keys in production when possible
- Monitor access: Review Stripe API logs and database access logs regularly
- Environment-specific values: Never use production database URLs or API keys in development
Troubleshooting
”POSTGRES_URL environment variable is not set”
This error occurs when the database client tries to connect without finding thePOSTGRES_URL variable. Make sure:
- Your
.envfile exists in the project root - The variable name is spelled correctly (case-sensitive)
- There are no extra spaces around the
=sign
Stripe webhook signature verification failed
This usually means:STRIPE_WEBHOOK_SECRETis incorrect or missing- The webhook secret doesn’t match the endpoint configuration
- In development, the
stripe listencommand isn’t running
Next Steps
Database Setup
Configure PostgreSQL and run migrations
Stripe Setup
Set up payment processing and webhooks