Environment Variables
Complete guide to configuring Unstack Pro environment variables
Environment Variables
All environment variables must be set in Convex. Set them locally in .env.local for development, but they must also be configured in your Convex environment for production.
Security Notice: Never commit your .env.local file to version control. Keep your secrets secure!
What You're Configuring
All environment variables must be set in your Convex environment. Set them in .env.local for local development, but replicate them in Convex for production:
- Convex: Database connection and deployment
- Resend: Email service (required for sign-in)
- Autumn: Billing (required for organizations)
- Secrets: Authentication and security keys
The auth system itself is already configured and working.
Quick Setup
Copy the example file and fill in your values:
cp .env.example .env.localRequired Variables
These variables must be set for the application to work:
Authentication
BETTER_AUTH_SECRET
Required: Yes
Type: String (Base64 encoded)
Where: Convex environment
Your secret key for Better Auth session encryption and security.
Generate with:
openssl rand -base64 32Example:
BETTER_AUTH_SECRET="dGhpcyBpcyBhIHNlY3JldCBrZXkgZm9yIGF1dGhlbnRpY2F0aW9u"This must be the same in both your .env.local file and Convex environment variables!
BETTER_AUTH_URL
Required: Yes
Type: URL
Where: Convex environment
The public URL where your application is accessible.
Development:
BETTER_AUTH_URL="http://localhost:3000"Production:
BETTER_AUTH_URL="https://yourdomain.com"OAuth callbacks and email links will use this URL. Make sure it matches your actual domain!
Convex Configuration
CONVEX_DEPLOYMENT
Required: Yes
Type: String
Where: .env.local (and Convex environment for production)
Your Convex deployment identifier.
Example:
CONVEX_DEPLOYMENT="dev:merry-bison-13"Get this by:
- Running
npx convex dev - Or from your Convex dashboard
NEXT_PUBLIC_CONVEX_URL
Required: Yes
Type: URL
Where: .env.local
Your Convex cloud deployment URL for client-side access.
Example:
NEXT_PUBLIC_CONVEX_URL="https://merry-bison-13.convex.cloud"Variables prefixed with NEXT_PUBLIC_ are exposed to the browser.
NEXT_PUBLIC_CONVEX_SITE_URL
Required: Yes
Type: URL
Where: .env.local
Your Convex site URL for hosting static assets and functions.
Example:
NEXT_PUBLIC_CONVEX_SITE_URL="https://merry-bison-13.convex.site"Application URLs
SITE_URL / NEXT_PUBLIC_APP_URL
Required: Yes
Type: URL
Where: .env.local
Your application's public URL. Used for generating absolute URLs in emails and redirects.
Development:
SITE_URL="http://localhost:3000"
NEXT_PUBLIC_APP_URL="http://localhost:3000"Production:
SITE_URL="https://yourdomain.com"
NEXT_PUBLIC_APP_URL="https://yourdomain.com"Email Configuration
Required for email verification, password resets, and notifications. Email verification is required for users to sign in.
RESEND_API_KEY
Required: For all environments
Type: String
Where: Convex environment
Your Resend API key for sending transactional emails.
Example:
RESEND_API_KEY="re_123456789abcdefghijklmnop"Get this by:
- Sign up at resend.com
- Create an API key in your dashboard
- Verify your sending domain (for production)
During development, you can use the test API key, but emails will only be sent to verified addresses.
EMAIL_FROM
Required: For all environments
Type: String (Email format)
Where: Convex environment
The sender email address and name for outgoing emails.
Example:
EMAIL_FROM="Unstack Pro <no-reply@auth.unstack.pro>"Format: "Display Name <email@domain.com>"
The domain must be verified in your Resend account for production use.
Passkey Configuration
PASSKEY_RP_ID
Required: For passkeys/WebAuthn
Type: String (Domain)
Where: .env.local
The Relying Party ID for WebAuthn/passkey authentication. Must match your domain.
Development:
PASSKEY_RP_ID="localhost"Production:
PASSKEY_RP_ID="yourdomain.com"The RP ID must match the domain where your app is hosted. For subdomains, I'd recommend the main domain (e.g., example.com not app.example.com) so that passkeys work across all subdomains.
Optional Variables
Payments
AUTUMN_API_KEY
Required: For organizations (per-seat billing)
Type: String
Where: Convex environment
Your Autumn API key for payment processing. Required for organization billing features.
Example:
AUTUMN_API_KEY="am_sk_test_key"Autumn is required for organizations. If you don't want billing, delete all Autumn-related code from your local clone.
Monitoring
Setting Convex Environment Variables
Some variables must also be set in Convex's environment. Use the Convex CLI:
# Set authentication secret
npx convex env set BETTER_AUTH_SECRET "your-secret-here"
# Set auth URL
npx convex env set BETTER_AUTH_URL "https://yourdomain.com"
# Set email configuration
npx convex env set RESEND_API_KEY "re_your-key-here"
npx convex env set EMAIL_FROM "Your App <no-reply@example.com>"
# Set billing configuration (required for organizations)
npx convex env set AUTUMN_API_KEY "am_your-key-here"You can view and manage Convex environment variables in your Convex dashboard.
Complete Example
Here's a complete .env.local file with all variables:
# Authentication
BETTER_AUTH_SECRET="dGhpcyBpcyBhIHNlY3JldCBrZXkgZm9yIGF1dGhlbnRpY2F0aW9u"
BETTER_AUTH_URL="https://dev.untraceable.dev"
# Email
RESEND_API_KEY="re_APIKEY"
EMAIL_FROM="Unstack Pro <no-reply@auth.unstack.pro>"
# Payments (required for organizations)
AUTUMN_API_KEY="am_sk_test_key"
# Application URLs
NEXT_PUBLIC_APP_URL="https://dev.untraceable.dev"
SITE_URL="https://dev.untraceable.dev"
# Convex
CONVEX_DEPLOYMENT="dev:merry-bison-13"
NEXT_PUBLIC_CONVEX_URL="https://merry-bison-13.convex.cloud"
NEXT_PUBLIC_CONVEX_SITE_URL="https://merry-bison-13.convex.site"
# Passkeys
PASSKEY_RP_ID="dev.untraceable.dev"Environment Variable Checklist
Before deploying, make sure:
-
BETTER_AUTH_SECRETis set in both.env.localand Convex - All URLs match your actual domain (no localhost in production)
-
PASSKEY_RP_IDmatches your domain - Email configuration is set up with verified domain
- Convex deployment is created and URLs are correct
-
.env.localis in.gitignore - Production secrets are different from development
Troubleshooting
Authentication Not Working
- Check
BETTER_AUTH_SECRETis the same everywhere - Verify
BETTER_AUTH_URLmatches your actual URL - Clear cookies and try again
Emails Not Sending
- Verify
RESEND_API_KEYis correct - Check domain is verified in Resend
- Ensure
EMAIL_FROMuses verified domain - Variables are set in both
.env.localand Convex
Passkeys Not Working
PASSKEY_RP_IDmust match your domain exactly- For local development, use
localhost - For production, use your root domain
Convex Connection Issues
- Run
npx convex devto ensure deployment is active - Check all three Convex URLs are correct
- Verify deployment exists in Convex dashboard
Security Best Practices
- Never commit secrets: Add
.env.localto.gitignore - Rotate secrets regularly: Especially
BETTER_AUTH_SECRET - Use different secrets: Development and production should have different values
- Restrict API keys: Use the minimum permissions necessary
- Monitor access: Review Convex and Resend logs regularly
Production Reminder: Always use HTTPS in production. Never use http:// URLs for BETTER_AUTH_URL or SITE_URL.