Auth

Clerk

A managed authentication service with ready React components for sign-in, profile and organizations.

What it is

Clerk provides ready UI components (<SignIn />, <UserButton />) and SDKs for Next.js, React, Expo and others. Sign-in, sign-up, MFA, passkeys and session management work out of the box.

It has built-in organizations and roles, handy for B2B SaaS. User data lives in Clerk, and you sync it to your database with webhooks.

The main advantage is integration speed and a polished developer experience. The tradeoff is dependency on the service and per-active-user pricing.

Use it when

  • You need polished ready sign-in in Next.js or React within an hour.
  • B2B SaaS that needs organizations and roles.
  • The team wants minimal authentication code.

Avoid it when

  • Identity data must stay on your own infrastructure: Keycloak.
  • Very price-sensitive projects with many free users.

Key concepts

Components
Ready SignIn, SignUp, UserButton, UserProfile.
Middleware
Protects routes at request level.
Organizations
Teams, roles and invitations for B2B.
Webhooks
Events for syncing users into your database.

Example

Protecting /dashboard routes in Next.js.

Interview questions

  1. 1. Where are users stored with Clerk?

    In Clerk. To link with your data model you store the userId and sync needed fields with webhooks.

  2. 2. How do you protect a route?

    With middleware that calls auth.protect() for private paths, and an auth() check in server components or APIs.

  3. 3. When is a self-hosted solution better?

    When you need control over data, no per-user fee or specific sign-in behavior the service does not allow.

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).