Running Clerk?

Clerk middleware looping or webhooks rejected? We fix it.

Clerk is the fastest way to get a usable signup and login into a Next.js app, and the fastest way to produce a redirect loop when the middleware config does not match the route structure. We work through the middleware, the webhook signing, the Organizations model and the auth() calls that are running in the wrong runtime, and leave the auth path predictable.

  • Since 2015Fixing technology
  • FreeEstimates
  • US teamReal engineers

clerk-middleware.log

still broken

What it is

Clerk at a glance

Clerk is a developer-focused authentication platform launched in 2020 by Colin Sidoti and Braden Sidoti. It ships drop-in components for React, Next.js, Remix, Expo and a handful of other frameworks, with a focus on the signup and login UI being usable out of the box rather than needing a week of styling work.

The product covers passwords, passkeys, social connections, multi-factor, Organizations, invitations, SAML for enterprise customers, and a webhook stream through Svix. Pricing has a generous free tier (10k MAU) and scales from there, with Organizations, SSO connections and Enhanced Security moving a project into the Pro or Enterprise tiers. Most problems we see are not with Clerk itself; they are with how the middleware, webhooks and runtime boundaries were wired into a Next.js app that grew faster than the auth code did.

Type
Developer-focused authentication and user management
First released
2020
License
Proprietary SaaS, MAU-based pricing with Free, Pro and Enterprise tiers
Maintained by
Clerk, Inc.
Typically used for
Next.js and React auth, B2B Organizations, enterprise SSO, webhook-driven user sync

The honest version

Clerk pros and cons

No technology is all upside. This is where Clerk earns its place and where it tends to cause trouble.

Where Clerk is strong

  • Drop-in UI components that look rightSignIn, SignUp, UserButton and OrganizationSwitcher render usable flows on day one, so product teams ship instead of styling password fields for two sprints.
  • Next.js App Router support is first classclerkMiddleware, auth() and currentUser() are designed for the App Router, with Edge and Node runtimes both supported out of the box.
  • Organizations and invites are built inMulti-tenant SaaS can model customer organizations, invite flows, role-based membership and per-org switching without rolling their own.
  • Passkeys and MFA without hand-rollingWebAuthn passkeys, TOTP, SMS, backup codes and session management are configurable in the dashboard, not reimplemented per project.
  • Webhooks via SvixUser, session and organization events arrive as signed webhooks with retries and a replay UI, so a background worker can keep a local user table in sync reliably.
  • Generous free tierUp to ten thousand monthly active users on the free plan is enough for most prototypes and many production apps to stay free indefinitely.

Where Clerk bites

  • Middleware is where everything goes wrongThe clerkMiddleware matcher has to include every protected route and exclude every public one, and a mis-scoped matcher is how teams produce redirect loops and public pages that require login.
  • Edge runtime limits biteauth() and currentUser() work in Edge, but some clerkClient calls do not, and routing them to the Node runtime means rethinking how a route handler is structured.
  • Webhook signing is non-obviousSvix signatures require exact raw body handling, and any middleware that parses JSON ahead of the verification breaks the signature check in a way that only surfaces in production.
  • Vendor lock-in on the hosted UIThe components are nice but tie you to Clerk's rendering. Fully custom flows exist, and once you go there the value proposition is closer to a plain auth API than to the drop-in promise.
  • Organizations plan boundary is tightThe free plan does not include Organizations, so the moment a product goes B2B it moves to a paid tier, sometimes earlier than the roadmap assumed.
  • Deprecation moves faster than long-lived projects likeauthMiddleware was replaced by clerkMiddleware, and APIs that were stable last year now carry migration guides. Projects that upgrade twice a year catch up; projects that upgrade once a year do not.

Sound familiar?

Common Clerk problems we fix

The Clerk problems that bring people to us, and what you have once each one is fixed.

too many redirects to /sign-in

Middleware is in a redirect loop

A matcher that protects the sign-in route itself, or a public page that was marked private by a broader matcher pattern. Users bounce between /sign-in and / forever.

Middleware honest, loops gone

Webhook signature mismatch (Svix)

Webhook events are being rejected

Body-parser middleware that read the raw body before the Svix verifier could sign-check it, or an environment variable that holds the wrong signing secret after a key rotation.

Webhooks verified and processed

auth() called in Pages Router without wrapper

auth() returns null in an API route

A Pages Router API route that was not wrapped with the required helper, or an App Router route that is running in a runtime where the auth context is not available.

auth() returns the real user

publishableKey mismatch

A preview deploy uses the wrong Clerk instance

Production keys set as defaults in the host config and used by a preview branch, so users from the main app can log in to preview environments and vice versa.

Keys scoped per environment

Organization: invite limit reached

Invites stop being sent

An Organizations plan boundary that nobody realized existed, or a soft limit on pending invites per org that was hit by a bulk onboarding script.

Invites flowing, limits understood

JWT expired: exp before iat

Sessions keep failing at boundary times

A server clock that is skewed against Clerk's issuance time, or a cache that is holding a token longer than its lifetime. Users log in and get rejected immediately.

Clocks aligned, sessions stable

social connection: invalid_client

Social login broke for one provider

A Google or Microsoft app whose credentials were rotated without updating Clerk, or a redirect URI that was tightened at the provider and no longer matches.

Social providers working

What we do

Clerk help, from middleware to Organizations

Reach out for one looping deploy, or let us own the whole Clerk integration.

Rescue
Middleware in a loop, webhooks rejected, sessions dropping. We get signup and login reliable before touching the long tail of nice-to-haves.
Next.js middleware and routing
clerkMiddleware matchers reviewed against the real route tree, public and protected routes made explicit, and auth() calls moved to the correct runtime.
Webhook sync
Svix signatures verified with the raw body, idempotent handlers that survive retries, and a local user table that actually reflects what Clerk thinks is true.
Organizations and B2B
Customer orgs modeled, invitations wired to onboarding, roles that match the product, and enterprise SAML connections for the customers who ask for them.
Migrations
Moving from NextAuth, Auth0 or a hand-rolled session system onto Clerk without a logout for the existing user base.
Managed Tech
Deprecations tracked across Clerk versions, webhook delivery health watched, MAU trend checked against the plan, and an engineer who already knows your middleware.

How it works

From first message to fixed

  1. Look Free estimate

    Tell us what's going wrong. We look at it, then tell you plainly what's wrong and what it will cost.

  2. Fix

    We fix the cause, not the symptom. If something is down, getting it back up comes first.

  3. Harden

    Backups, monitoring, updates and access, so the same problem can't quietly come back.

  4. Hand back or stay on

    You get a plain-language write-up. Or we stay on for hosting, upkeep and new work.

Often found together

Running Clerk alongside something else?

We work on the whole stack, so the problem can be wherever it actually is.

Questions

Clerk questions

Something else? Call+1 737 727 7327

Why is my Clerk middleware causing a redirect loop?

Almost always because the matcher is protecting a route that Clerk itself needs to be public, like /sign-in or /sign-up, or because a route that renders the sign-in component is behind the matcher. The fix is to make the matcher explicit about which routes require auth and which do not, and to verify every entry in the pattern against the actual route tree.

How do I verify Clerk webhooks correctly?

Clerk uses Svix for webhook signing, and the verifier requires the exact raw body that was signed. Any JSON parsing middleware that runs before the verifier will change the body subtly and break the signature. The fix is to read the raw body as a buffer, verify the Svix signature, and only then parse the JSON, with the signing secret stored per environment.

Should we move from NextAuth to Clerk?

If you are already shipping and NextAuth is working, probably not. The migration cost is real: user records need to be imported, session cookies change shape, and any custom callbacks have to be rewritten as Actions or webhooks. If you are starting a new Next.js project or your NextAuth setup has grown into a maintenance burden, Clerk is often the faster path. We will give the honest answer against your actual codebase.

Why does auth() return null in some of my routes?

The common causes are a route that is not covered by the clerkMiddleware matcher, a Pages Router API route that was not wrapped with the required helper, or an Edge runtime call that is running outside the context. The fix depends on which, and we usually find it in a few minutes by walking the middleware matcher against the route file tree.

Can Clerk handle enterprise SSO for our B2B customers?

Yes, through SAML connections on the Pro or Enterprise plan, scoped per Organization. Each customer org can have its own SAML provider, and users from that org are routed to it at signin. We set the connection up with the customer's IdP, verify the attribute mapping and leave it documented so future customer configurations are repeatable.

How much does Clerk help cost?

The estimate is free. Send over the repo or a note on what is looping or failing, and we return a scope and a fixed price before any changes go into the middleware.

Free estimate

Clerk giving you trouble?

Middleware, webhooks, Organizations, SSO and the Next.js runtime questions nobody wants to answer twice.

  • No charge to find out what it will take
  • If it's urgent, say so

Replies come from a person. By sending, you authorize us to email you back. No marketing.