Clerk
Managed authentication with prebuilt UI components — zero infrastructure
Overview
Clerk is a fully managed authentication and user management platform. You embed their React components (SignIn, SignUp, UserButton) and Clerk handles everything: UI, sessions, MFA, device management, social OAuth, and user data storage — all on their infrastructure.
Unlike library-based solutions, your users are stored in Clerk's database. Your app receives a JWT (Clerk session token) that you validate using their SDK or middleware. This trades data ownership for zero operational overhead.
Clerk's free tier is generous (10,000 MAUs), and their dashboard gives you a full user management UI out of the box. The SDK works seamlessly with Next.js App Router, including server components and middleware.
Architecture fit
Fully managed — you call their API and embed their components. Users are stored on their infrastructure, not yours.
Key features
Trade-offs
Zero infrastructure — no DB schema, no migrations, no ops
User data lives on Clerk's servers — data residency concerns
Prebuilt UI that matches your theme — fastest time to auth
Expensive at scale ($0.02/MAU above free tier)
Organizations, MFA, passkeys out of the box
Vendor lock-in — migrating users out is painful
First-class Next.js App Router + Middleware support
Customisation limited to what Clerk exposes in their SDK
✓ When to use
- →Startups that want auth done in a day with no ops burden
- →Apps where prebuilt UI quality matters more than customisation
- →Teams that need organizations + RBAC without building it
- →Projects under 10k MAU (generous free tier)
✗ When NOT to use
- →Data residency requirements (EU GDPR, healthcare, finance)
- →Scale where per-MAU pricing becomes prohibitive (>100k users)
- →Need full control over the authentication database schema
- →Apps that need deep customisation of auth UI flows
Implementation
TypeScript// middleware.ts — protect all routes
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
const isPublic = createRouteMatcher(["/", "/sign-in(.*)", "/sign-up(.*)"]);
export default clerkMiddleware((auth, req) => {
if (!isPublic(req)) auth().protect();
});
// app/layout.tsx — wrap with ClerkProvider
import { ClerkProvider } from "@clerk/nextjs";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return <ClerkProvider><html><body>{children}</body></html></ClerkProvider>;
}
// app/sign-in/[[...sign-in]]/page.tsx
import { SignIn } from "@clerk/nextjs";
export default function Page() {
return <SignIn />;
}
// Server Component — read session
import { auth, currentUser } from "@clerk/nextjs/server";
const { userId } = await auth();
if (!userId) redirect("/sign-in");
const user = await currentUser();
// Client Component
import { useAuth, useUser } from "@clerk/nextjs";
const { isSignedIn, userId } = useAuth();In production
Uses Clerk for user authentication across their AI search product
Clerk powers auth including organizations for team workspaces
Clerk is the default auth choice for most Vercel-deployed Next.js startups
Other frameworks
Better Auth
TypeScript-first, self-hosted authentication with full schema ownership
Auth.js (NextAuth v5)
The most popular authentication library for Next.js and the JS ecosystem
Lucia
Minimal session management primitives — you control the auth logic
Passport.js
The original Node.js authentication middleware — 500+ strategies