Secret Configuration
Secret Configuration
Section titled “Secret Configuration”This guide covers setting up Wrangler secrets for Splinterpic. Never commit secrets to git!
Security Best Practices
Section titled “Security Best Practices”Before setting secrets:
- Never commit secrets to version control
- Use different secrets for dev/staging/production
- Rotate secrets regularly (every 90 days recommended)
- Use strong, randomly generated secrets (minimum 32 characters)
- Limit access to secrets to authorized team members only
- Monitor usage for unauthorized access attempts
Required Secrets
Section titled “Required Secrets”1. JWT_SECRET (REQUIRED)
Section titled “1. JWT_SECRET (REQUIRED)”Purpose: Signs authentication tokens
Generate a secure secret:
# Generate random 32-byte secretnode -e "console.log(require('crypto').randomBytes(32).toString('base64'))"Set the secret:
npx wrangler secret put JWT_SECRET# Paste the generated secret when prompted⚠️ Critical: App will crash without this secret!
2. STRIPE_SECRET_KEY (REQUIRED for payments)
Section titled “2. STRIPE_SECRET_KEY (REQUIRED for payments)”Purpose: Stripe API authentication
Get your key:
- Go to: https://dashboard.stripe.com/apikeys
- Copy your Secret Key (starts with
sk_live_orsk_test_)
Set the secret:
npx wrangler secret put STRIPE_SECRET_KEY# Paste your sk_live_... or sk_test_... keyFor development: Use test keys (sk_test_...)
3. STRIPE_WEBHOOK_SECRET (REQUIRED for subscriptions)
Section titled “3. STRIPE_WEBHOOK_SECRET (REQUIRED for subscriptions)”Purpose: Verifies Stripe webhook signatures
Setup webhook first:
- Go to: https://dashboard.stripe.com/webhooks
- Click “Add endpoint”
- Endpoint URL:
https://api.splinterpic.app/api/webhooks/stripe - Select events:
checkout.session.completedinvoice.payment_succeededinvoice.payment_failedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deleted
- Copy the Signing Secret (starts with
whsec_...)
Set the secret:
npx wrangler secret put STRIPE_WEBHOOK_SECRET# Paste the whsec_... secretOptional Secrets
Section titled “Optional Secrets”4. GITHUB_CLIENT_SECRET (Optional)
Section titled “4. GITHUB_CLIENT_SECRET (Optional)”Purpose: GitHub OAuth authentication
Setup:
- Go to: https://github.com/settings/developers
- Create or edit OAuth App
- Set Authorization callback URL:
https://splinterpic.app/auth/github/callback - Copy Client Secret
Set the secret:
npx wrangler secret put GITHUB_CLIENT_SECRET# Paste GitHub Client SecretNote: Also update GITHUB_CLIENT_ID in wrangler.toml [vars] section
5. GOOGLE_CLIENT_SECRET (Optional)
Section titled “5. GOOGLE_CLIENT_SECRET (Optional)”Purpose: Google OAuth authentication
Setup:
- Go to: https://console.cloud.google.com/apis/credentials
- Create OAuth 2.0 Client ID
- Set redirect URI:
https://splinterpic.app/auth/google/callback - Copy Client Secret
Set the secret:
npx wrangler secret put GOOGLE_CLIENT_SECRET# Paste Google Client SecretNote: Also update GOOGLE_CLIENT_ID in wrangler.toml [vars] section
6. MAILERSEND_API_TOKEN (Optional)
Section titled “6. MAILERSEND_API_TOKEN (Optional)”Purpose: Magic link email authentication
Setup:
- Go to: https://www.mailersend.com/
- Get API token from dashboard
Set the secret:
npx wrangler secret put MAILERSEND_API_TOKEN# Paste MailerSend API tokenVerification
Section titled “Verification”After setting secrets, verify:
npx wrangler secret listExpected output:
┌──────────────────────────┐│ Name │├──────────────────────────┤│ JWT_SECRET ││ STRIPE_SECRET_KEY ││ STRIPE_WEBHOOK_SECRET ││ GITHUB_CLIENT_SECRET ││ GOOGLE_CLIENT_SECRET ││ MAILERSEND_API_TOKEN │└──────────────────────────┘Environment-Specific Secrets
Section titled “Environment-Specific Secrets”Development
Section titled “Development”# Use test mode for Stripenpx wrangler secret put STRIPE_SECRET_KEY# Paste sk_test_... keyProduction
Section titled “Production”# Use live mode for Stripenpx wrangler secret put STRIPE_SECRET_KEY# Paste sk_live_... keySecret Rotation
Section titled “Secret Rotation”Rotate secrets periodically for security:
# 1. Generate new secretNEW_SECRET=$(node -e "console.log(require('crypto').randomBytes(32).toString('base64'))")
# 2. Update secretecho $NEW_SECRET | npx wrangler secret put JWT_SECRET
# 3. Redeploy workernpm run worker:deploy
# 4. Update any local copiesImportant: Rotating JWT_SECRET will invalidate all active sessions!
Troubleshooting
Section titled “Troubleshooting”Secret not working
Section titled “Secret not working”Check secret is set:
npx wrangler secret listRedeploy after setting:
npm run worker:deployStripe webhook failing
Section titled “Stripe webhook failing”Verify webhook URL:
- Should be:
https://api.splinterpic.app/api/webhooks/stripe - Must be publicly accessible
Check signing secret:
- Get from Stripe Dashboard → Webhooks
- Should start with
whsec_
OAuth not working
Section titled “OAuth not working”Verify callback URLs match:
- GitHub:
https://splinterpic.app/auth/github/callback - Google:
https://splinterpic.app/auth/google/callback
Check Client IDs:
- Set in
wrangler.toml[vars] section - Must match provider settings
Security Checklist
Section titled “Security Checklist”Before going to production:
- All required secrets set
- Using live Stripe keys (not test)
- Webhook signing secret configured
- JWT_SECRET is strong and unique
- OAuth secrets set (if using)
- Secrets verified with
wrangler secret list - Worker redeployed after setting secrets
-
.envfiles not committed to git -
.gitignoreincludes.env* - Team members have limited access to secrets
Best Practices
Section titled “Best Practices”- Use a Password Manager: Store backup copies of secrets securely
- Document Secret Owners: Know who has access to what
- Audit Access: Review secret access logs regularly
- Automate Rotation: Set calendar reminders for quarterly rotation
- Use Separate Accounts: Different Stripe accounts for dev/prod
- Monitor Usage: Watch for unusual API usage patterns
- Have Rollback Plan: Know how to quickly rotate compromised secrets
Quick Setup Script
Section titled “Quick Setup Script”For rapid setup (after generating secrets manually):
#!/bin/bash# setup-secrets.sh - Run this script to set all secrets
echo "Setting JWT_SECRET..."npx wrangler secret put JWT_SECRET
echo "Setting STRIPE_SECRET_KEY..."npx wrangler secret put STRIPE_SECRET_KEY
echo "Setting STRIPE_WEBHOOK_SECRET..."npx wrangler secret put STRIPE_WEBHOOK_SECRET
echo "Secrets setup complete!"npx wrangler secret listMake executable: chmod +x setup-secrets.sh
Next: Production Deployment