- You are hitting Clerk’s MAU pricing tiers and the cost stops matching the value.
- Your product now needs AI agents as first-class entities, an MCP OAuth 2.1 server, or per-agent trust scoring. Clerk does not model any of that.
- You want full control over session cookies, token issuance, and audit logs.
- Compliance needs (GDPR export, self-hosted data residency) are easier with a local service.
- You rely heavily on Clerk’s hosted sign-in / sign-up components and have no designer bandwidth to rebuild them. KavachOS ships headless building blocks, not a dashboard you drop in.
- You use Clerk’s B2B Organizations extensively with their admin UI. KavachOS has an organization plugin but no hosted admin console yet.
- You need Clerk-specific features like device attestation at the sign-in edge or their waitlist product.
Concepts map
Server setup
Next.js App Router route handler
Clerk hides its route handling behind the middleware. KavachOS exposes an explicit handler so you can see and control what runs.middleware.ts
Clerk’sclerkMiddleware does three things: verifies the session cookie, attaches auth to the request, and optionally protects routes. KavachOS does not ship an equivalent wrapper. Roll your own, or only protect at the page level using getSession().
getSession returns a Result type ({ success, data } or { success: false, error }), not a thrown exception. See the configuration page for full signatures.
Client SDK
Hooks
Sign-in and sign-up pages
Clerk ships<SignIn /> and <SignUp /> components that render their hosted flow inside your layout. KavachOS gives you hooks and expects you to build the form.
useSignIn({ factor: 'passkey' }), useSignIn({ factor: 'phone' }). See auth flows for the full list.
Organizations
Clerk’s Organizations model ports cleanly. The Kavach organization plugin uses the same three concepts: organization, membership, role.org:admin, org:member role prefix becomes plain role strings in Kavach. If you have code reading orgMembership.role, search for org: and strip the prefix.
OAuth providers
Clerk configures OAuth providers in its dashboard. KavachOS does it in code. Side by side for GitHub and Google:https://<your-clerk>.clerk.accounts.dev/v1/oauth_callback/<provider> to https://<your-domain>/api/auth/oauth/<provider>/callback. Do this before cutover so the first sign-in after the switch works.
Data migration
Clerk’s data lives in Clerk’s cloud. You export it, then import it. Clerk exposes a Backend API and an SDK. Pagination caps at 500 per page.Step 1: export users from Clerk
Step 2: import into the Kavach tables
Kavach uses PBKDF2-SHA256 for password hashing. Clerk uses bcrypt. The hashes are not compatible, so password sign-in will not work for imported users until they go through password reset or their next sign-in (see next sign-in rehash below). OAuth and passkey sign-ins work immediately.Next sign-in rehash
If you want password sign-in to keep working without a forced reset, accept Clerk bcrypt hashes during a transition window and rehash to PBKDF2 on successful sign-in. The shape of the hook:verifyLegacyHash hook and force password reset for any stragglers.
Session cookies
Clerk sets the__session cookie signed by Clerk’s keys. KavachOS cannot read those cookies without calling Clerk. That means one of two things:
- Hard cutover. All signed-in users sign in once on the KavachOS flow. Simpler. Set an expectation with a banner for a few days.
- Side-by-side with a rollout flag. Keep Clerk running for a percentage of traffic while KavachOS takes the rest. Each user picks one stack until you flip them to 100% KavachOS. Sample middleware below.
Rollback
Keep Clerk wired up on a different subdomain while you roll out.KAVACHOS_ROLLOUT=10, watch error rates and sign-in conversions, raise to 100 over a week or two. Cut the Clerk app once traffic is zero.
FAQ
Will my users be signed out on cutover day? Yes, unless you run a side-by-side rollout. Clerk session cookies cannot be verified without Clerk, so KavachOS cannot accept them. A one-time sign-in is the simplest story. Tell users ahead of time and keep the old subdomain alive as a fallback. Do OAuth tokens survive the migration? No. Clerk does not export live OAuth access or refresh tokens. Users re-authorise the provider on first sign-in after migration. If your app calls provider APIs using those tokens, plan for a grace period. Does KavachOS have an equivalent of Clerk’s Organizations UI? Not hosted. Theorganization plugin has the same model (organization, membership, role). You build the UI. The example app has a minimal organization page to copy.
What about Clerk’s waitlist, age gate, or impersonation features?
- Waitlist: not in KavachOS core. Gate sign-up in your own route handler.
- Age gate: use the
additionalFieldsconfig to collect DOB and enforce in middleware. - Impersonation with TTL: the
adminplugin ships this.
jwt plugin exposes a customClaims callback that runs at token issuance. It receives the session and returns any extra claims you want in the JWT.
Can I keep Clerk for B2B and use KavachOS for B2C in the same app?
Technically yes, but you will spend more time on the boundary than on the migration itself. Pick one.