Configuration & Environment Variables
Copy .env.local.example to .env.local, then fill keys from Supabase, Stripe, OpenAI/Anthropic, and any optional providers. Nothing in this section belongs in client-side bundles except the explicitly NEXT_PUBLIC_* vars.
1. Supabase Setup
-
Go to the Supabase Dashboard and select your project.
-
Navigate to Settings (gear icon) > API.
-
URL: Copy the Project URL.
-
Anon Key: Copy the key labeled
anon / public. -
Service Role Key: Copy the key labeled
service_role / secret.
⚠️ Warning: The SUPABASE_SERVICE_ROLE_KEY is for server-side use only. Never expose it in the browser.
OAuth Providers Setup
To enable Google and GitHub OAuth login:
-
Navigate to Authentication > Providers in your Supabase dashboard.
-
For Google OAuth:
- Click on Google provider
- Toggle Enable Google provider to ON
- Go to Google Cloud Console
- Create a new project or select an existing one
- Go to Credentials > Create Credentials > OAuth client ID
- Choose Web application
- Add authorized redirect URIs:
https://YOUR_PROJECT_REF.supabase.co/auth/v1/callback
- Copy the Client ID and Client Secret
- Paste them into Supabase Google provider settings
- Click Save
-
For GitHub OAuth:
- Click on GitHub provider
- Toggle Enable GitHub provider to ON
- Go to GitHub Developer Settings
- Click New OAuth App
- Fill in:
- Application name: Your app name
- Homepage URL: Your app URL (e.g.,
http://localhost:3000for dev) - Authorization callback URL:
- For development:
https://YOUR_PROJECT_REF.supabase.co/auth/v1/callback - For production:
https://YOUR_PROJECT_REF.supabase.co/auth/v1/callback
- For development:
- Click Register application
- Copy the Client ID and generate a Client Secret
- Paste them into Supabase GitHub provider settings
- Click Save
⚠️ Important: Make sure to use your actual Supabase project reference in the callback URLs. You can find it in your Supabase project URL (e.g., https://xxxxx.supabase.co).
Supabase Auth Redirect URLs (required)
This template redirects auth flows back to your app at /callback (see src/app/(auth)/callback/route.ts).
In Supabase Dashboard → Authentication → URL Configuration:
- Site URL: set to your app URL (matches
NEXT_PUBLIC_APP_URL) - Redirect URLs: add (at least)
http://localhost:3000/callbackhttps://your-domain.com/callback(production)
2. Stripe Setup
-
Log in to the Stripe Dashboard.
-
API Keys: Go to Developers > API Keys.
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: Found under "Standard keys." (optional for this template unless you add client-side Stripe Elements)STRIPE_SECRET_KEY: Found under "Standard keys" (click to reveal).
-
Optional portal URL
NEXT_PUBLIC_STRIPE_PORTAL_URLis optional. The template uses a server-side Billing Portal session (POST /api/billing/portal) by default, so you can omit this unless you add your own portal link in the UI.
-
Webhook Secret:
- Install the Stripe CLI.
- Run
stripe listen --forward-to localhost:3000/api/webhooks/stripe. - Copy the
whsec_...key printed in the terminal.
-
Price IDs:
- Go to Product Catalog.
- Create products for Pro, Top-up, and Enterprise tiers.
- Click into each product to find the API ID for the price (starts with
price_...).
3. AI Providers
OpenAI
-
Go to the OpenAI Platform.
-
Navigate to API Keys in the left sidebar.
-
Click Create new secret key.
-
Copy the key (starts with
sk-proj-...).
Anthropic
-
Go to the Anthropic Console.
-
Navigate to API Keys.
-
Click Create Key.
-
Copy the key (starts with
sk-ant-...).
4. App Configuration
NEXT_PUBLIC_APP_URL
- For local development: Use
http://localhost:3000 - For production: Use your actual domain (e.g.,
https://your-app.com)
.env.local Template
Create a .env.local file in the root of your project with the following structure:
# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
# Stripe
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
NEXT_PUBLIC_STRIPE_PORTAL_URL=your_optional_portal_url
STRIPE_PRO_PRICE_ID=price_...
STRIPE_TOPUP_PRICE_ID=price_...
STRIPE_ENTERPRISE_PRICE_ID=price_...
# AI Providers
OPENAI_API_KEY=sk-proj-...
ANTHROPIC_API_KEY=sk-ant-...
# App
NEXT_PUBLIC_APP_URL=http://localhost:3000
# Cron (recommended if using /api/cron/reset-credits)
CRON_SECRET=your_random_secret_here
Next Steps
After setting up your environment variables:
- Run the database schema from
src/db/schema.sqlin your Supabase SQL editor. - Create a storage bucket named
uploadsin Supabase Storage. - Start the development server with
pnpm dev.