skip to content

For a startup's new Express API, how would you choose between hand-wired Passport, Auth.js, better-auth and Clerk, and what does leaving each one cost?

level: principalimportance: should knowfreq 35%

answer

  1. who holds the user rows
  2. what you still have to build
  3. 0.x and experimental
  4. per-user billing versus engineering time
  5. exit: code rewrite or data migration

basics

~20 s

Choose by who holds users and what you must build: Passport only authenticates requests, Auth.js and better-auth bring endpoints with data in your database, Clerk hosts everything. Leaving the first three is a code rewrite; leaving Clerk also migrates users.

solid answer

~50 s

I compare four things. **What I still build**: Passport authenticates requests but mounts no routes and assumes no schema, so sign-up, reset, verification and second factors are ours; Auth.js brings OAuth, email-link and session endpoints but deliberately limits passwords; better-auth brings email and password, social sign-in and plugins such as `twoFactor` and `organization`; Clerk brings hosted screens and user management. **Who holds the data**: our database for Passport and better-auth, our database or nothing for Auth.js depending on its adapter, the vendor for Clerk. **Maturity**: `@auth/express` is 0.x and documented as experimental. **Exit**: off Passport, Auth.js or better-auth it is a code rewrite against data we own; off Clerk it is also a user migration, where whether password hashes can be exported decides whether everyone resets. For a small team that wants its data, I default to a mounted library and pick a hosted provider only when time to market outweighs that exit.

go deeper

for a junior

Recall where each option keeps users: your schema for Passport, your database for better-auth, an adapter for Auth.js, the vendor for Clerk.

for a middle

Explain what each option leaves you to build, from Passport's bare request authentication to Clerk's hosted screens.

for a senior

Show how the choice changes operations: migrations and secrets for the libraries, keys and vendor dependence for a hosted provider.

for a principal

Make the call as a recorded decision: data ownership, maturity of the integration, per-user cost and a written exit plan for the option chosen.

## The decision a lead actually owns A new Express API needs sign-in, and the team can assemble it from **Passport** strategies, mount a library that brings its own endpoints (**Auth.js** through `@auth/express`, or **better-auth** through `toNodeHandler`), or hand identity to a hosted provider (**Clerk** through `@clerk/express`). There is no single right answer. Each option moves work, data and risk to a different place, and the team carries that for years. The general question of running versus renting an authorization server is covered in the OAuth integration material; this is the Express-level version: which package sits in front of your routes, and what it implies. ## Comparing the four | | Hand-wired Passport | Auth.js (`@auth/express`) | better-auth | Clerk (`@clerk/express`) | |---|---|---|---|---| | Mounts | Your own routes calling `passport.authenticate` | `app.use('/auth', ExpressAuth(config))` | `app.all('/api/auth/*splat', toNodeHandler(auth))` | `app.use(clerkMiddleware())` | | Users stored | Your schema | Adapter tables, or nowhere without an adapter | `user`, `account` tables in your database | At the vendor | | Sessions | `express-session` and a store, or tokens | Encrypted JWT cookie, or adapter rows | `session` table rows | Vendor-issued session tokens | | Built in | Request authentication through strategies | OAuth/OIDC providers, email links, passkeys (experimental) | Email and password, social providers, plugins | Hosted sign-up, sign-in, user management | | Maturity signal | Long-established | 0.x, documented experimental | 1.x | Commercial SDK | ## What each option leaves you to build - **Passport.** Its README says it is there "to authenticate requests" and that it "does not mount routes or assume any particular database schema". Sign-up, password hashing, email verification, password reset, account linking, second factors and session-store wiring are your code. Maximum control and the most surface to secure. - **Auth.js.** OAuth and OIDC sign-in, the callback, CSRF and sessions come built in. Its `Credentials` provider is intentionally limited, and its users are not persisted, so a password-first product rebuilds much of what Passport would have needed. Email links and passkeys need an adapter; passkeys also need an experimental flag. - **better-auth.** `emailAndPassword: { enabled: true }`, `socialProviders` and plugins (`twoFactor`, `magicLink`, `emailOTP`, `organization`, `admin`) cover most of a startup's list, at the price of a schema the library defines and grows with each plugin. - **Clerk.** Almost nothing to build; the work moves into vendor configuration, and every request depends on Clerk tokens and keys. ## The exit cost, option by option 1. **From Passport**: the cheapest exit. The data and the code are yours; replacing it means rewriting sign-in routes, not moving users. 2. **From Auth.js**: with an adapter, the users and accounts tables are yours in Auth.js's shape; without one there is no user data to move. Either way you rewrite the mount, every `getSession` call and the client's sign-in calls. Because `@auth/express` is 0.x, budget for API changes even if you stay. 3. **From better-auth**: data in your database, in its `user`, `session`, `account` and `verification` shape. Password hashes are on `account` rows, so a new system must verify that hash format or force resets. 4. **From Clerk**: the hardest exit. The users and their credentials sit with the vendor. Whether the vendor exports password hashes in a format you can verify decides whether every user must reset a password, and every `getAuth` call, the front-end sign-in components and any `clerkClient` lookups must be rewritten. ## Cost beyond the exit - **Money.** A hosted provider bills by usage, typically per active user, so the bill grows with success; the libraries cost engineering time instead. - **Operations.** With Passport, Auth.js or better-auth you run the database, the secret rotation and the migrations; with Clerk you run integration and key management. - **Security ownership.** Hand-built flows put password storage, rate limiting and reset-token handling in your review scope; a library narrows that; a host takes most of it. ## A reasonable default and when to deviate For a small team that wants its data and fast delivery, a mounted library that keeps users in your database (better-auth, or Auth.js with an adapter) is a defensible default; Auth.js fits when sign-in is mostly OAuth providers and the team accepts a 0.x integration. Clerk fits when shipping this quarter matters more than the later migration, ideally recorded as a decision with the exit written down. Hand-wired Passport fits when requirements are unusual enough that a library's schema or flows would fight you.

  • What would make you move a team from hand-wired Passport to a mounted library?
    When the backlog fills with identity plumbing the library already ships: verification emails, password reset, linked social accounts, a second factor. Each is security-sensitive code the team must keep reviewing. If a library's schema can absorb the existing users, a migration usually costs less than maintaining that surface by hand.
  • How do you reduce the exit cost if the team chooses Clerk anyway?
    Keep Clerk behind one module: a single middleware turns `getAuth(req)` into your own `req.user` shape, and handlers never import `@clerk/express`. Keep your own users table keyed by the Clerk user id for domain data. Write the exit plan down when you adopt it, including how password hashes would leave.

  • Says Passport ships sign-up, password reset and session storage
  • Treats @auth/express as a stable, long-term API with no upgrade risk
  • Assumes leaving a hosted provider is only a code change
  • Chooses on setup time alone, ignoring who holds the user data
  • Claims the libraries all store users in the same schema