Loading...
Loading...
Troubleshoot common Clerk errors and issues. Use when encountering authentication errors, SDK issues, or configuration problems with Clerk. Trigger with phrases like "clerk error", "clerk not working", "clerk authentication failed", "clerk issue", "fix clerk".
npx skill4agent add jeremylongshore/claude-code-plugins-plus-skills clerk-common-errorsError: Clerk: Invalid API key# Verify keys in .env.local match Clerk dashboard
# Publishable key starts with pk_test_ or pk_live_
# Secret key starts with sk_test_ or sk_live_
# Check for trailing whitespace
cat -A .env.local | grep CLERK
# Ensure correct environment
echo $NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYError: useAuth can only be used within the <ClerkProvider /> component// Ensure ClerkProvider wraps entire app in layout.tsx
import { ClerkProvider } from '@clerk/nextjs'
export default function RootLayout({ children }) {
return (
<ClerkProvider>
<html><body>{children}</body></html>
</ClerkProvider>
)
}Error: Session not found// Handle gracefully in your app
const { userId } = await auth()
if (!userId) {
redirect('/sign-in')
}Error: form_identifier_not_found// Show helpful message to user
catch (err: any) {
if (err.errors?.[0]?.code === 'form_identifier_not_found') {
setError('No account found with this email. Please sign up.')
}
}Error: form_password_incorrectcatch (err: any) {
if (err.errors?.[0]?.code === 'form_password_incorrect') {
setError('Incorrect password. Try again or reset your password.')
}
}Error: Too many redirects// middleware.ts
const isPublicRoute = createRouteMatcher([
'/sign-in(.*)', // Must include sign-in pages
'/sign-up(.*)',
'/'
])
export default clerkMiddleware(async (auth, request) => {
if (!isPublicRoute(request)) {
await auth.protect()
}
})Error: Routes not protectedexport const config = {
matcher: [
// Skip static files and _next
'/((?!_next|[^?]*\\.(?:html?|css|js|jpe?g|webp|png|gif|svg|ttf|woff2?|ico)).*)',
'/',
'/(api|trpc)(.*)'
]
}Error: Text content does not match server-rendered HTML'use client'
import { useUser } from '@clerk/nextjs'
export function UserGreeting() {
const { user, isLoaded } = useUser()
// Prevent hydration mismatch by waiting for load
if (!isLoaded) {
return <div>Loading...</div>
}
return <div>Hello, {user?.firstName}</div>
}Error: Cannot read properties of undefined (reading 'userId')// Server Component - use auth()
import { auth } from '@clerk/nextjs/server'
const { userId } = await auth()
// Client Component - use useAuth()
'use client'
import { useAuth } from '@clerk/nextjs'
const { userId } = useAuth()Error: Webhook signature verification failed// app/api/webhooks/clerk/route.ts
import { Webhook } from 'svix'
import { headers } from 'next/headers'
export async function POST(req: Request) {
const WEBHOOK_SECRET = process.env.CLERK_WEBHOOK_SECRET!
const headerPayload = await headers()
const svix_id = headerPayload.get('svix-id')
const svix_timestamp = headerPayload.get('svix-timestamp')
const svix_signature = headerPayload.get('svix-signature')
const body = await req.text()
const wh = new Webhook(WEBHOOK_SECRET)
const evt = wh.verify(body, {
'svix-id': svix_id!,
'svix-timestamp': svix_timestamp!,
'svix-signature': svix_signature!
})
// Process event
}# Check Clerk version
npm list @clerk/nextjs
# Verify environment variables
npx next info
# Check for multiple Clerk instances
npm list | grep clerk
# Clear Next.js cache
rm -rf .next && npm run dev| Error Code | Meaning | Quick Fix |
|---|---|---|
| User doesn't exist | Show sign-up link |
| Wrong password | Show reset link |
| Already logged in | Redirect to app |
| Code expired | Resend code |
| Too many attempts | Wait and retry |
clerk-debug-bundle