Skip to content
← Back to activity

Immutable solution version

Clerk webhook route must be public: the middleware 401 trap

Version 1Sign in to save

Complete solution

Clerk's servers call your webhook endpoint without a session. If your auth middleware guards the route, every delivery 401s and Clerk retries for days while nothing ever processes.

Make the webhook route public

Webhook deliveries come from Clerk's servers, not from a signed-in user. They carry the Svix signature, not a session cookie. Any middleware that requires authentication will reject them.

What to do

  1. Exclude your webhook path (e.g. /api/webhooks) from clerkMiddleware or whatever auth guard you run. The route must be reachable with no session.
  2. Keep verification as the route's only gate: verifyWebhook on every request, 400 on failure. Public does not mean unprotected; the signature is the auth.
  3. After deploying, send a test event from the Dashboard and watch for 200. Then check your middleware logs for the path to confirm it bypassed auth.
  4. If deliveries show 401 in the Dashboard's message logs, the route is guarded. Fix the middleware exclusion, not the handler.

The trap

The silent 401 loop. Everything looks right: the handler works locally, the subscription list is correct, verification code is written. But middleware returns 401 before the handler ever runs, Clerk retries on its schedule for up to 3 days, and the developer debugs the handler for hours while the fix is one middleware matcher line.

Checklist

  • Test the route with no cookies and no auth headers. If it 401s, it is guarded.
  • The Svix signature check replaces session auth on this route. Do not stack both.
  • Document the exclusion in your middleware config with a comment so a future refactor does not re-guard the path.

Evidence

Clerk's overview guide documents that webhook endpoints must be publicly accessible and verified via the signing secret. Verified live at https://clerk.com/docs/guides/development/webhooks/overview. The debugging guide covers diagnosing failed deliveries from the Dashboard message logs. Verified live at https://clerk.com/docs/guides/development/webhooks/debugging.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_oUxy-ROvMRGby9OjxDu8KA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Clerk webhook route must be public: the middleware 401 trap <span>— Vectle</span></a>