Environment Setup Guide
Required Environment Variables
Create a .env.local file in the project root with these variables:
# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
# Server-only key for Secrets Vault encryption (64-char hex, 32 bytes)
SECRETS_ENCRYPTION_KEY=your-64-char-hex-key
# Application URL (for production)
NEXT_PUBLIC_APP_URL=https://apbks.com
# Optional audit compliance (all off / keep-forever by default)
# AUDIT_RETENTION_DAYS=365
# AUDIT_CRON_SECRET=replace-me
# AUDIT_SYSLOG_URL=udp://loghost:514
# AUDIT_SIEM_WEBHOOK_URL=https://siem.example/hooks/audit
# High-entropy HMAC key, >=32 bytes — not a human password:
# AUDIT_SIEM_WEBHOOK_SECRET=$(openssl rand -base64 32)
# Self-hosted secret-client mTLS only. Leave unset (cloudflare) in hosted production.
# MTLS_MODE=proxy
# MTLS_PROXY_FINGERPRINT_HEADER=X-SSL-Client-Fingerprint
# MTLS_PROXY_VERIFY_HEADER=X-SSL-Client-Verify
# MTLS_PROXY_SHARED_SECRET=<private random token from openssl rand -hex 32>
# MTLS_TRUSTED_PROXIES=172.28.0.10/32OAuth Configuration (CRITICAL)
OAuth redirect URLs must be configured in the Supabase Dashboard, not in code.
Supabase Dashboard Settings
- Go to Supabase Dashboard → Authentication → URL Configuration
- Set Site URL to your production domain:
https://apbks.com- Add Redirect URLs for both production and development:
https://apbks.com/**
http://localhost:3000/**GitHub OAuth Setup
- Go to GitHub Developer Settings → OAuth Apps
- Create new OAuth App or edit existing:
https://apbks.com
- Authorization callback URL: https://.supabase.co/auth/v1/callback - Copy the Client ID and Client Secret to Supabase:
Google OAuth Setup
- Go to Google Cloud Console → Credentials
- Create OAuth 2.0 Client ID:
https://apbks.com
- http://localhost:3000
- Authorized redirect URIs:
- https://.supabase.co/auth/v1/callback - Copy credentials to Supabase:
LinkedIn OAuth Setup
- Create new app and configure:
https://.supabase.co/auth/v1/callback - Copy credentials to Supabase:
Cloudflare Pages Deployment
When deploying to Cloudflare Pages, set these environment variables:
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SECRETS_ENCRYPTION_KEY=your-64-char-hex-key
NEXT_PUBLIC_APP_URL=https://apbks.comCommon Issues
OAuth redirects to localhost in production
Cause: Supabase "Site URL" is set to localhost or missing.
Fix: Set Site URL to https://apbks.com in Supabase Dashboard → Authentication → URL Configuration.
404 on OAuth callback
Cause: GitHub/Google OAuth callback URL is incorrect.
Fix: Ensure callback URL is https:// (NOT your app domain).
Secrets creation fails with "Internal Server Error"
Cause: SECRETS_ENCRYPTION_KEY is missing or invalid in your runtime environment.
Fix:
- Generate a key:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
- Set it as
SECRETS_ENCRYPTION_KEYin your deployment environment. - Redeploy/restart the app.