Frontend Environment Variables
Frontend environment variables are stored in a.env.local file in the root directory.
Required Variables
The
.env.local file is automatically created when you run npx convex dev for the first time. The Convex CLI will populate it with your deployment name.Backend Environment Variables
Backend environment variables are configured in your Convex deployment. You can set them through the Convex Dashboard or using the Convex CLI.Authentication
Evaly uses Convex Auth with Google OAuth for authentication.Create Google OAuth Credentials
- Go to Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth 2.0 Client ID
- Configure the consent screen if prompted
- Set Application type to Web application
- Add authorized redirect URIs:
http://localhost:3000/api/auth/callback/google(development)https://yourdomain.com/api/auth/callback/google(production)
File Storage (Cloudflare R2)
Evaly uses Cloudflare R2 for file storage. This is required for uploading images in questions and handling file attachments.Create R2 Bucket
- Log in to Cloudflare Dashboard
- Go to R2 in the sidebar
- Click Create bucket
- Choose a bucket name (e.g.,
evaly-uploads) - Select a location and create the bucket
Generate API Token
- In the R2 dashboard, click Manage R2 API Tokens
- Click Create API Token
- Set permissions to Object Read & Write
- Scope it to your bucket
- Copy the Access Key ID, Secret Access Key, and Endpoint URL
Set Up Public Access (Optional)
For public file access, connect your bucket to a custom domain:
- Go to your bucket settings
- Click Connect Domain
- Add your domain (e.g.,
cdn.yourdomain.com) - Update your DNS records as instructed
- Use this domain as your
R2_CDN_URL
Alternatively, you can enable public access directly on the bucket and use the R2.dev domain.
Email Service (Plunk)
Evaly uses Plunk for sending transactional emails (invitations, password resets, notifications).Create Plunk Account
- Sign up at useplunk.com
- Verify your sending domain
- Copy your API key from the dashboard
Email sending is optional for development. If not configured, the system will log a warning but continue functioning. Emails simply won’t be sent.
AI Question Generation (Google Gemini)
Evaly can generate questions using AI. This requires a Google Gemini API key.Get Gemini API Key
- Go to Google AI Studio
- Sign in with your Google account
- Click Get API Key or Create API Key
- Copy the generated API key
JWT Configuration (Auto-Generated)
These variables are automatically generated by Convex Auth. Do not set these manually unless migrating from another deployment.Complete Configuration Example
Here’s a complete example of all environment variables:Managing Environment Variables
View All Variables
Update a Variable
Remove a Variable
Switch Between Deployments
Convex allows you to have multiple deployments (dev, staging, production):Environment-Specific Configuration
Development
- Use
http://localhost:3000forSITE_URL - Use separate R2 buckets for development
- Consider using test API keys where available
Production
- Use your production domain for
SITE_URL - Use production R2 buckets with CDN
- Ensure all API keys are production-ready
- Set up proper monitoring and logging
Security Best Practices
- Use different credentials for development and production
- Rotate API keys regularly
- Use Convex’s built-in environment variable management instead of
.envfiles for the backend - Restrict R2 bucket permissions to only what’s needed
- Monitor API usage to detect unauthorized access
Troubleshooting
Authentication Not Working
- Verify OAuth redirect URIs match exactly
- Check that
SITE_URLmatches your application URL - Ensure Google OAuth consent screen is configured
File Uploads Failing
- Verify R2 credentials are correct
- Check bucket permissions allow read/write
- Ensure
R2_CDN_URLis accessible publicly
Emails Not Sending
- Verify Plunk API key is valid
- Check that sending domain is verified in Plunk
- Review Plunk dashboard for delivery errors
AI Generation Not Available
- Ensure
GOOGLE_GENERATIVE_AI_API_KEYis set - Verify the API key has proper permissions
- Check Google AI Studio quota limits
Next Steps
- Learn how to Deploy to Production
- Review the Architecture Overview
- Explore the Database Schema