Cron Secret Tokens Setup Guide
This guide explains how to generate and configure secret tokens for cron jobs.
What Are Secret Tokens?
Secret tokens are random strings used to authenticate cron job requests. They prevent unauthorized access to your cron endpoints. Think of them as passwords for your automated jobs.
Generating Secret Tokens
You need to create strong, random strings for each secret. Here are several methods:
Method 1: Using OpenSSL (Recommended)
# Generate a 32-character random hex string
openssl rand -hex 32
# Or generate a 64-character base64 string
openssl rand -base64 64
Method 2: Using Node.js
# In your terminal
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Method 3: Using Online Generators
Recommended length: 32-64 characters
Method 4: Using Python
python3 -c "import secrets; print(secrets.token_urlsafe(32))"
Required Secret Tokens
Based on your cron jobs, you need these secrets:
Required (Must Have)
WORKOUT_WINDOW_CRON_SECRET- Used by: Workout Window chains, Workout Window battles
- Also used as fallback for: Chat analysis, Drops, DreamPro
Optional (Can Share or Use Separate)
-
CHAT_CRON_SECRET- Used by: Note analysis cron
- Falls back to:
WORKOUT_WINDOW_CRON_SECRETif not set
-
DROPS_CRON_SECRET- Used by: Daily drops generation, Monthly drops award
- Falls back to:
WORKOUT_WINDOW_CRON_SECRETorCHAT_CRON_SECRETif not set
-
ENCOURAGEMENT_DROPS_CRON_SECRET- Used by: Engagement processing
- Falls back to:
DROPS_CRON_SECRETorWORKOUT_WINDOW_CRON_SECRETif not set
-
SPOTIFY_SYNC_CRON_SECRET- Used by: Spotify sync cron
- No fallback - must be set if using Spotify sync
-
DREAMPRO_CRON_SECRET- Used by: DreamPro step prompts
- Falls back to:
WORKOUT_WINDOW_CRON_SECRETif not set
Quick Setup (Simplest Approach)
Option 1: Use One Secret for Everything
Generate one secret and use it for all:
# Generate one secret
openssl rand -hex 32
# Example output: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6
Then set these environment variables to the same value:
WORKOUT_WINDOW_CRON_SECRETCHAT_CRON_SECRETDROPS_CRON_SECRETENCOURAGEMENT_DROPS_CRON_SECRETSPOTIFY_SYNC_CRON_SECRETDREAMPRO_CRON_SECRET
Option 2: Use Separate Secrets (More Secure)
Generate a unique secret for each:
# Generate 6 different secrets
for i in {1..6}; do
echo "Secret $i: $(openssl rand -hex 32)"
done
Where to Set Environment Variables
Vercel (Frontend)
- Go to your Vercel project dashboard
- Click Settings → Environment Variables
- Add each variable:
- Name:
WORKOUT_WINDOW_CRON_SECRET - Value:
your-generated-secret-here - Environment: Select all (Production, Preview, Development)
- Name:
- Repeat for all secrets
- Important: After adding variables, redeploy your project
Railway (Backend)
- Go to your Railway project dashboard
- Click on your backend service
- Go to Variables tab
- Add each variable:
- Key:
WORKOUT_WINDOW_CRON_SECRET - Value:
your-generated-secret-here
- Key:
- Repeat for all secrets
- Railway will automatically redeploy when you add variables
Important: Keep Secrets in Sync
The same secret must be set in both Vercel AND Railway for each cron job to work.
For example:
- If
WORKOUT_WINDOW_CRON_SECRETin Vercel isabc123 - Then
WORKOUT_WINDOW_CRON_SECRETin Railway must also beabc123
Example Setup Script
Here's a script to generate all secrets at once:
#!/bin/bash
echo "Generating cron secrets..."
echo ""
echo "WORKOUT_WINDOW_CRON_SECRET=$(openssl rand -hex 32)"
echo "CHAT_CRON_SECRET=$(openssl rand -hex 32)"
echo "DROPS_CRON_SECRET=$(openssl rand -hex 32)"
echo "ENCOURAGEMENT_DROPS_CRON_SECRET=$(openssl rand -hex 32)"
echo "SPOTIFY_SYNC_CRON_SECRET=$(openssl rand -hex 32)"
echo "DREAMPRO_CRON_SECRET=$(openssl rand -hex 32)"
echo ""
echo "Copy these values to:"
echo "1. Vercel Environment Variables"
echo "2. Railway Environment Variables"
Save as generate-secrets.sh, make executable (chmod +x generate-secrets.sh), and run it.
Verification
After setting up secrets, test a cron endpoint:
# Test from your local machine (replace with your actual values)
curl -X POST https://your-frontend.vercel.app/api/cron/workout-window/generate-chains
# Should return either:
# - Success response (if secrets match)
# - 401 Unauthorized (if secrets don't match)
# - 500 error (if secret not configured)
Security Best Practices
- Never commit secrets to git - They should only be in environment variables
- Use different secrets for production and development if needed
- Rotate secrets periodically (every 6-12 months)
- Use strong random strings (at least 32 characters)
- Don't share secrets in chat, email, or documentation
Troubleshooting
Error: "WORKOUT_WINDOW_CRON_SECRET not configured"
- Solution: Add the secret to Vercel environment variables and redeploy
Error: 401 Unauthorized
- Solution: Check that the secret in Vercel matches the secret in Railway
Error: Cron job not running
- Solution:
- Check Vercel dashboard → Cron Jobs tab
- Verify environment variables are set
- Check that
NEXT_PUBLIC_API_URLis set correctly in Vercel
Quick Reference
| Secret Name | Required? | Used By | Fallback |
|---|---|---|---|
WORKOUT_WINDOW_CRON_SECRET | ✅ Yes | Chains, Battles | None |
CHAT_CRON_SECRET | ⚠️ Optional | Note Analysis | WORKOUT_WINDOW_CRON_SECRET |
DROPS_CRON_SECRET | ⚠️ Optional | Daily/Monthly Drops | WORKOUT_WINDOW_CRON_SECRET |
ENCOURAGEMENT_DROPS_CRON_SECRET | ⚠️ Optional | Engagement | DROPS_CRON_SECRET |
SPOTIFY_SYNC_CRON_SECRET | ⚠️ Optional | Spotify Sync | None |
DREAMPRO_CRON_SECRET | ⚠️ Optional | DreamPro | WORKOUT_WINDOW_CRON_SECRET |
Minimum setup: Just set WORKOUT_WINDOW_CRON_SECRET and most jobs will work (except Spotify sync if you use it).