Skip to content

Environment Variables

Product Factory requires environment variables configured per app and worker. In development, use .dev.vars files in each worker directory. In production, set them in the Cloudflare dashboard or via Wrangler secrets.

Gateway Worker

VariableRequiredDescription
ALLOWED_ORIGINSYes (prod)Comma-separated list of allowed CORS origins (e.g., https://app.example.com,https://admin.example.com). In development mode, all origins are allowed.

Service bindings (AUTH_SERVICE, BILLING_SERVICE, etc.) are configured in wrangler.toml, not as environment variables.

Auth Worker

VariableRequiredDescription
JWT_SECRETYesSecret key for Better Auth session signing
AUTH_BASE_URLYesPublic base URL for auth callbacks
RESEND_API_KEYYesResend API key for transactional emails
TURNSTILE_SECRETNoCloudflare Turnstile secret key for bot protection
GOOGLE_CLIENT_IDNoGoogle OAuth client ID (enables Google login)
GOOGLE_CLIENT_SECRETNoGoogle OAuth client secret
GITHUB_CLIENT_IDNoGitHub OAuth client ID (enables GitHub login)
GITHUB_CLIENT_SECRETNoGitHub OAuth client secret
OPS_WEBHOOK_URLNoDiscord/Feishu webhook for new user notifications

OAuth providers are automatically enabled when both client ID and secret are set. Login method toggles (email/password, Google, GitHub) are managed via the admin auth settings UI and stored in D1.

Admin Worker

VariableRequiredDescription
GOOGLE_CLIENT_IDRecommended for OAuth admin UILets the admin auth settings page report Google as configured
GOOGLE_CLIENT_SECRETRecommended for OAuth admin UILets the admin auth settings page report Google as configured
GITHUB_CLIENT_IDRecommended for OAuth admin UILets the admin auth settings page report GitHub as configured
GITHUB_CLIENT_SECRETRecommended for OAuth admin UILets the admin auth settings page report GitHub as configured

Billing Worker

VariableRequiredDescription
JWT_SECRETYesShared secret for internal token verification
STRIPE_SECRET_KEYConditionalStripe API key (if using Stripe)
STRIPE_WEBHOOK_SECRETConditionalStripe webhook signing secret
CREEM_API_KEYConditionalCreem API key (if using Creem)
CREEM_WEBHOOK_SECRETConditionalCreem webhook signing secret
OPS_WEBHOOK_URLNoWebhook for payment notifications

AI Worker

VariableRequiredDescription
AI_GATEWAY_ACCOUNT_IDNoCloudflare AI Gateway account ID
AI_GATEWAY_IDNoCloudflare AI Gateway ID
OPS_WEBHOOK_URLNoWebhook for AI error notifications

AI provider API keys are stored in D1, not as environment variables. If the AI Gateway IDs are omitted, the app falls back to provider base URLs directly.

Support Worker

VariableRequiredDescription
JWT_SECRETYesShared secret for internal token verification
NEWSLETTER_HMAC_SECRETRecommendedHMAC secret for newsletter confirm/unsubscribe tokens (falls back to JWT_SECRET)
TURNSTILE_SECRETNoCloudflare Turnstile secret key for newsletter bot protection
RESEND_API_KEYYesResend API key for newsletter and support emails
RESEND_FROM_EMAILYesSender email address (e.g., noreply@example.com)
OPS_WEBHOOK_URLNoWebhook for support notifications

Frontend Apps

VariableRequiredDescription
GATEWAY_URLYesGateway API URL for SSR middleware session verification
PUBLIC_SUPPORT_APIYes (web)Support worker URL for newsletter subscribe (web app only)
PUBLIC_APP_KEYYes (web)Application key for API requests (web app only)
PUBLIC_TURNSTILE_SITE_KEYNoCloudflare Turnstile site key
PUBLIC_UMAMI_WEBSITE_IDNoUmami analytics website ID
PUBLIC_UMAMI_SRCNoUmami tracking script URL
PUBLIC_GA4_IDNoGoogle Analytics 4 measurement ID
PUBLIC_SITE_URLRecommended (web)Public web site URL used for canonical tags, robots.txt, and sitemap.xml
PUBLIC_DOCS_URLRecommendedDocs site URL used for navigation links, docs canonical tags, and docs sitemap generation

Setting Secrets

Development

Create .dev.vars in each worker directory. For example:

apps/worker-auth/.dev.vars
JWT_SECRET=dev-secret-key-at-least-32-chars!!
RESEND_API_KEY=re_test_xxxxx
# apps/worker-billing/.dev.vars
JWT_SECRET=dev-secret-key-at-least-32-chars!!
STRIPE_SECRET_KEY=sk_test_xxxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxxx
# or:
# CREEM_API_KEY=creem_test_xxxxx
# CREEM_WEBHOOK_SECRET=your_creem_webhook_secret
# apps/worker-support/.dev.vars
JWT_SECRET=dev-secret-key-at-least-32-chars!!
RESEND_API_KEY=re_test_xxxxx
RESEND_FROM_EMAIL=noreply@example.com

Production

Terminal window
pnpm --filter worker-auth wrangler secret put JWT_SECRET
pnpm --filter worker-auth wrangler secret put RESEND_API_KEY
pnpm --filter worker-billing wrangler secret put STRIPE_SECRET_KEY
pnpm --filter worker-billing wrangler secret put STRIPE_WEBHOOK_SECRET
# or:
# pnpm --filter worker-billing wrangler secret put CREEM_API_KEY
# pnpm --filter worker-billing wrangler secret put CREEM_WEBHOOK_SECRET

Billing CLI Helpers

From the repo root:

Terminal window
pnpm billing:setup:stripe-cli
pnpm billing:setup:creem-cli
pnpm billing:check-env
pnpm billing:listen:stripe
pnpm billing:whoami:creem