Clerk Production Checklist
Overview
Complete checklist to ensure your Clerk integration is production-ready. Covers environment config, security hardening, monitoring, error handling, and compliance.
Prerequisites
- Clerk integration working in development
- Production environment and domain configured
- CI/CD pipeline ready
Instructions
Step 1: Environment Configuration Checklist
| Check |
Status |
Action |
Using pk_live_ keys |
[ ] |
Switch from test to live keys |
CLERK_SECRET_KEY is sk_live_ |
[ ] |
Never use test keys in production |
.env.local in .gitignore |
[ ] |
Prevent accidental secret commits |
CLERK_WEBHOOK_SECRET set |
[ ] |
Required for webhook verification |
| Production domain in Clerk Dashboard |
[ ] |
Dashboard > Domains |
| Sign-in/sign-up URLs configured |
[ ] |
Set NEXT_PUBLIC_CLERK_SIGN_IN_URL etc. |
Step 2: Validation Script
// scripts/prod-readiness.ts
import { createClerkClient } from '@clerk/backend'
async function validateProduction() {
const checks: { name: string; pass: boolean; detail: string }[] = []
// 1. Live keys check
const pk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY || ''
const sk = process.env.CLERK_SECRET_KEY || ''
checks.push({
name: 'Live publishable key',
pass: pk.startsWith('pk_live_'),
detail: pk.startsWith('pk_live_') ? 'Using live key' : `Using ${pk.slice(0, 8)}... (should be pk_live_)`,
})
checks.push({
name: 'Live secret key',
pass: sk.startsWith('sk_live_'),
detail: sk.startsWith('sk_live_') ? 'Using live key' : 'Should be sk_live_ for production',
})
// 2. API connectivity
try {
const clerk = createClerkClient({ secretKey: sk })
await clerk.users.getUserList({ limit: 1 })
checks.push({ name: 'API connectivity', pass: true, detail: 'Backend API reachable' })
} catch (err: any) {
checks.push({ name: 'API connectivity', pass: false, detail: err.message })
}
// 3. Webhook secret
checks.push({
name: 'Webhook secret configured',
pass: !!process.env.CLERK_WEBHOOK_SECRET,
detail: process.env.CLERK_WEBHOOK_SECRET ? 'Set' : 'CLERK_WEBHOOK_SECRET missing',
})
// 4. Middleware exists
const fs = await import('fs')
const hasMiddleware = fs.existsSync('middleware.ts') || fs.existsSync('src/middleware.ts')
checks.push({
name: 'Middleware present',
pass: hasMiddleware,
detail: hasMiddleware ? 'Found' : 'middleware.ts not found at project root',
})
// Print results
console.log('\n=== Clerk Production Readiness ===\n')
for (const check of checks) {
const icon = check.pass ? 'PASS' : 'FAIL'
console.log(`[${icon}] ${check.name}: ${check.detail}`)
}
const allPass = checks.every((c) => c.pass)
console.log(`\nResult: ${allPass ? 'READY for production' : 'NOT READY — fix failing checks'}`)
process.exit(allPass ? 0 : 1)
}
validateProduction()
Run with:
npx tsx scripts/prod-readiness.ts
Step 3: Security Checklist
| Check |
Status |
Action |
| Middleware protects all routes |
[ ] |
Verify non-public routes require auth |
API routes check userId |
[ ] |
Return 401 if userId is null |
| Webhook signatures verified |
[ ] |
Use svix library for verification |
| CORS configured correctly |
[ ] |
Only allow production domain |
| Rate limiting on sensitive endpoints |
[ ] |
Use @upstash/ratelimit or similar |
| CSP headers set |
[ ] |
Add Clerk domains to Content-Security-Policy |
| No secret keys in client code |
[ ] |
CLERK_SECRET_KEY never exposed |
Step 4: Monitoring Checklist
| Check |
Status |
Action |
| Health check endpoint |
[ ] |
/api/health monitoring Clerk API |
| Error tracking (Sentry) |
[ ] |
Clerk user context in error reports |
| Auth event logging |
[ ] |
Log sign-in, sign-out, permission denied |
| Webhook monitoring |
[ ] |
Alert on failed webhook deliveries |
| Uptime monitoring |
[ ] |
External monitor hitting health endpoint |
Step 5: Error Handling Checklist
| Check |
Status |
Action |
| Custom error pages |
[ ] |
/not-found, /error pages handle auth errors |
| Graceful auth failures |
[ ] |
Redirect to sign-in, don't show stack traces |
| Webhook retry handling |
[ ] |
Idempotency keys prevent duplicate processing |
| Session expiry UX |
[ ] |
Show "session expired" prompt, not blank page |
// app/error.tsx — global error boundary with auth context
'use client'
import { useAuth } from '@clerk/nextjs'
export default function Error({ error, reset }: { error: Error; reset: () => void }) {
const { isSignedIn } = useAuth()
return (
<div>
<h2>Something went wrong</h2>
<p>{error.message}</p>
<button again</button>
{!isSignedIn && <a href="/sign-in">Sign in</a>}
</div>
)
}
Step 6: Performance Checklist
| Check |
Status |
Action |
| Middleware matcher excludes static files |
[ ] |
Don't auth-check images, fonts, CSS |
User data cached (React.cache()) |
[ ] |
Deduplicate within request |
| Auth components lazy loaded |
[ ] |
dynamic() for UserButton, SignInButton |
| Edge Runtime for middleware |
[ ] |
Faster cold starts on Vercel |
Output
- Environment configuration verified (live keys, webhook secret, domain)
- Automated validation script (run in CI or before deploy)
- Security, monitoring, error handling, and performance checklists
- Global error boundary component with auth context
Error Handling
| Error |
Cause |
Solution |
| Validation script fails |
Test keys in production |
Switch to pk_live_ / sk_live_ keys |
| API connectivity check fails |
Wrong secret key |
Verify key in Clerk Dashboard > API Keys |
| Middleware not found |
File in wrong location |
Place middleware.ts at project root (not inside app/) |
| Health check returns 503 |
Clerk API unreachable |
Check network, verify key, check status.clerk.com |
Examples
CI Production Gate
# .github/workflows/deploy.yml — add as pre-deploy step
- name: Clerk production readiness
run: npx tsx scripts/prod-readiness.ts
env:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.CLERK_PK_PROD }}
CLERK_SECRET_KEY: ${{ secrets.CLERK_SK_PROD }}
CLERK_WEBHOOK_SECRET: ${{ secrets.CLERK_WEBHOOK_SECRET_PROD }}
Resources
Next Steps
Proceed to clerk-upgrade-migration for SDK version upgrades.
1---2name: clerk-prod-checklist3description: Production readiness checklist for Clerk deployment. Use when preparing to deploy, reviewing production configuration, or auditing Clerk implementation before launch. Trigger with phrases like "clerk production", "clerk deploy checklist", "clerk go-live", "clerk launch ready".4license: MIT5---6# Clerk Production Checklist78## Overview9Complete checklist to ensure your Clerk integration is production-ready. Covers environment config, security hardening, monitoring, error handling, and compliance.1011## Prerequisites12- Clerk integration working in development13- Production environment and domain configured14- CI/CD pipeline ready1516## Instructions1718### Step 1: Environment Configuration Checklist1920| Check | Status | Action |21|-------|--------|--------|22| Using `pk_live_` keys | [ ] | Switch from test to live keys |23| `CLERK_SECRET_KEY` is `sk_live_` | [ ] | Never use test keys in production |24| `.env.local` in `.gitignore` | [ ] | Prevent accidental secret commits |25| `CLERK_WEBHOOK_SECRET` set | [ ] | Required for webhook verification |26| Production domain in Clerk Dashboard | [ ] | Dashboard > Domains |27| Sign-in/sign-up URLs configured | [ ] | Set `NEXT_PUBLIC_CLERK_SIGN_IN_URL` etc. |2829### Step 2: Validation Script30```typescript31// scripts/prod-readiness.ts32import { createClerkClient } from '@clerk/backend'3334async function validateProduction() {35 const checks: { name: string; pass: boolean; detail: string }[] = []3637 // 1. Live keys check38 const pk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY || ''39 const sk = process.env.CLERK_SECRET_KEY || ''40 checks.push({41 name: 'Live publishable key',42 pass: pk.startsWith('pk_live_'),43 detail: pk.startsWith('pk_live_') ? 'Using live key' : `Using ${pk.slice(0, 8)}... (should be pk_live_)`,44 })45 checks.push({46 name: 'Live secret key',47 pass: sk.startsWith('sk_live_'),48 detail: sk.startsWith('sk_live_') ? 'Using live key' : 'Should be sk_live_ for production',49 })5051 // 2. API connectivity52 try {53 const clerk = createClerkClient({ secretKey: sk })54 await clerk.users.getUserList({ limit: 1 })55 checks.push({ name: 'API connectivity', pass: true, detail: 'Backend API reachable' })56 } catch (err: any) {57 checks.push({ name: 'API connectivity', pass: false, detail: err.message })58 }5960 // 3. Webhook secret61 checks.push({62 name: 'Webhook secret configured',63 pass: !!process.env.CLERK_WEBHOOK_SECRET,64 detail: process.env.CLERK_WEBHOOK_SECRET ? 'Set' : 'CLERK_WEBHOOK_SECRET missing',65 })6667 // 4. Middleware exists68 const fs = await import('fs')69 const hasMiddleware = fs.existsSync('middleware.ts') || fs.existsSync('src/middleware.ts')70 checks.push({71 name: 'Middleware present',72 pass: hasMiddleware,73 detail: hasMiddleware ? 'Found' : 'middleware.ts not found at project root',74 })7576 // Print results77 console.log('\n=== Clerk Production Readiness ===\n')78 for (const check of checks) {79 const icon = check.pass ? 'PASS' : 'FAIL'80 console.log(`[${icon}] ${check.name}: ${check.detail}`)81 }8283 const allPass = checks.every((c) => c.pass)84 console.log(`\nResult: ${allPass ? 'READY for production' : 'NOT READY — fix failing checks'}`)85 process.exit(allPass ? 0 : 1)86}8788validateProduction()89```9091Run with:92```bash93npx tsx scripts/prod-readiness.ts94```9596### Step 3: Security Checklist9798| Check | Status | Action |99|-------|--------|--------|100| Middleware protects all routes | [ ] | Verify non-public routes require auth |101| API routes check `userId` | [ ] | Return 401 if `userId` is null |102| Webhook signatures verified | [ ] | Use `svix` library for verification |103| CORS configured correctly | [ ] | Only allow production domain |104| Rate limiting on sensitive endpoints | [ ] | Use `@upstash/ratelimit` or similar |105| CSP headers set | [ ] | Add Clerk domains to Content-Security-Policy |106| No secret keys in client code | [ ] | `CLERK_SECRET_KEY` never exposed |107108### Step 4: Monitoring Checklist109110| Check | Status | Action |111|-------|--------|--------|112| Health check endpoint | [ ] | `/api/health` monitoring Clerk API |113| Error tracking (Sentry) | [ ] | Clerk user context in error reports |114| Auth event logging | [ ] | Log sign-in, sign-out, permission denied |115| Webhook monitoring | [ ] | Alert on failed webhook deliveries |116| Uptime monitoring | [ ] | External monitor hitting health endpoint |117118### Step 5: Error Handling Checklist119120| Check | Status | Action |121|-------|--------|--------|122| Custom error pages | [ ] | `/not-found`, `/error` pages handle auth errors |123| Graceful auth failures | [ ] | Redirect to sign-in, don't show stack traces |124| Webhook retry handling | [ ] | Idempotency keys prevent duplicate processing |125| Session expiry UX | [ ] | Show "session expired" prompt, not blank page |126127```typescript128// app/error.tsx — global error boundary with auth context129'use client'130import { useAuth } from '@clerk/nextjs'131132export default function Error({ error, reset }: { error: Error; reset: () => void }) {133 const { isSignedIn } = useAuth()134135 return (136 <div>137 <h2>Something went wrong</h2>138 <p>{error.message}</p>139 <button onClick={reset}>Try again</button>140 {!isSignedIn && <a href="/sign-in">Sign in</a>}141 </div>142 )143}144```145146### Step 6: Performance Checklist147148| Check | Status | Action |149|-------|--------|--------|150| Middleware matcher excludes static files | [ ] | Don't auth-check images, fonts, CSS |151| User data cached (`React.cache()`) | [ ] | Deduplicate within request |152| Auth components lazy loaded | [ ] | `dynamic()` for `UserButton`, `SignInButton` |153| Edge Runtime for middleware | [ ] | Faster cold starts on Vercel |154155## Output156- Environment configuration verified (live keys, webhook secret, domain)157- Automated validation script (run in CI or before deploy)158- Security, monitoring, error handling, and performance checklists159- Global error boundary component with auth context160161## Error Handling162| Error | Cause | Solution |163|-------|-------|----------|164| Validation script fails | Test keys in production | Switch to `pk_live_` / `sk_live_` keys |165| API connectivity check fails | Wrong secret key | Verify key in Clerk Dashboard > API Keys |166| Middleware not found | File in wrong location | Place `middleware.ts` at project root (not inside `app/`) |167| Health check returns 503 | Clerk API unreachable | Check network, verify key, check status.clerk.com |168169## Examples170171### CI Production Gate172```yaml173# .github/workflows/deploy.yml — add as pre-deploy step174- name: Clerk production readiness175 run: npx tsx scripts/prod-readiness.ts176 env:177 NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.CLERK_PK_PROD }}178 CLERK_SECRET_KEY: ${{ secrets.CLERK_SK_PROD }}179 CLERK_WEBHOOK_SECRET: ${{ secrets.CLERK_WEBHOOK_SECRET_PROD }}180```181182## Resources183- [Clerk Production Checklist](https://clerk.com/docs/deployments/overview)184- [Clerk Security Best Practices](https://clerk.com/docs/security/overview)185- [Clerk Domain Setup](https://clerk.com/docs/deployments/set-up-your-domain)186187## Next Steps188Proceed to `clerk-upgrade-migration` for SDK version upgrades.189