<arch.design/>
saasmanagedManaged SaaS

Clerk

Managed authentication with prebuilt UI components — zero infrastructure

clerk.com

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

managedManaged SaaS

Fully managed — you call their API and embed their components. Users are stored on their infrastructure, not yours.

Key features

Prebuilt <SignIn />, <SignUp />, <UserButton /> components
Organizations + roles + permissions
Multi-factor authentication (TOTP, SMS, backup codes)
Social OAuth, passkeys, magic links, phone OTP
Device session management
User impersonation for support workflows
Webhooks on auth events (user.created, session.ended…)
Bot detection and rate limiting built-in

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

Perplexity

Uses Clerk for user authentication across their AI search product

Loom

Clerk powers auth including organizations for team workspaces

Many YC startups

Clerk is the default auth choice for most Vercel-deployed Next.js startups

Other frameworks

← Back to Authentication