db3.aiVisit main site

11 October 2026

4 TypeScript Authentication Frameworks Compared: Sessions, Permissions, and Backend Fit

TL;DR

For a TypeScript authentication framework, choose Better Auth when you want a dedicated, framework-agnostic auth layer; Passport.js when you want modular authentication middleware in an existing Node.js app; AdonisJS Auth when you are building on AdonisJS; or db3.ai Auth when authentication should live alongside your TypeScript application's data and background services. None of these choices removes the need to authorize each private record or tenant-scoped action.

A login demo is easy to admire. A production identity boundary has to survive password recovery, device logout, an API request for somebody else's record, and a job that executes after the user has signed out. We compare four different ways to own those boundaries rather than treating every package with a sign-in method as interchangeable.

This list is for engineering teams building multi-user web applications, APIs, and AI products. We selected options with official documentation and distinct integration models: a dedicated auth framework, strategy-based middleware, an application-framework auth package, and auth inside a broader application runtime. For every option, we assess best fit, identity methods, session design, authorization integration, operating responsibility, and cost model. We do not assign a universal winner because the application and the authentication component own different pieces of the problem.

Table of contents

What should a TypeScript auth framework actually handle?

At a minimum, identify where a user account lives, how password or external-provider credentials attach to it, how a later request proves it belongs to the account, and how access ends. Then draw the boundary around what the framework does not enforce. A verified session identifies a caller; it does not prove the caller may read a particular conversation, workspace, or customer record. OWASP treats missing checks on client-selected object IDs as a distinct API security failure. Its object-level authorization guidance calls for checking permission on each object operation.

Sessions also deserve their own design review. Compare database-backed sessions, cookies, and bearer tokens in terms of expiration, refresh or rotation, revocation, device management, and validation at the server boundary. Ask whether changing a password invalidates existing sessions and how quickly a revoked credential stops working. A session identifier is sensitive even if it is opaque: OWASP's session management guidance explains how authenticated sessions carry the user's security context.

Four authentication architecture paths connecting identity verification, sessions, record access and background workers

1. Better Auth: Dedicated, framework-agnostic authentication

Screenshot of better-auth.com

Best fit: A TypeScript team that wants substantial authentication functionality without adopting an entire application framework. Better Auth's introduction describes a framework-agnostic auth system with an extension ecosystem. Its email-and-password guide documents built-in password sign-up and sign-in, while its organization plugin adds member, team, role, and permission concepts. Check the exact plugin and adapter your stack needs rather than assuming every feature is active by default.

Sessions and authorization: Better Auth documents cookie-based server sessions, expiration and refresh controls, session listing, and revocation. Optional session caching and secondary storage make it important to test revocation under the configuration you actually deploy, not just with a default development database. Organization roles can supply useful membership information, but your application still has to decide whether this actor may use this document or invoke this tool. The session management guide is the place to inspect those trade-offs.

Integration, limitations, and cost model: Plan for auth schema migrations, an application database or supported storage choice, frontend-to-backend session transport, and policy tests against your own records. The broad plugin surface is an advantage if you need multiple identity paths; it also creates configuration and upgrade decisions. Budget for database, hosting, email delivery, and operational support rather than assuming an auth package includes the surrounding infrastructure. Choose Better Auth when a dedicated, configurable auth layer fits an existing TypeScript stack better than a new app runtime.

2. Passport.js: Composable authentication in an existing Node.js backend

Screenshot of www.passportjs.org

Best fit: A team with an Express-compatible Node.js backend that wants to select and control its own authentication mechanisms. Passport is middleware rather than a complete TypeScript application framework. Its strategies documentation explains that mechanisms such as password and OpenID Connect are installed as separate strategy packages. That flexibility is attractive when an existing application already has an identity table and a deliberately chosen server architecture.

Sessions and authorization: Passport's session documentation uses the application's session middleware and application-defined serialization and deserialization. For an Express integration, it shows express-session as a separate dependency. You must decide where session state is stored, which user fields enter it, how logout and revocation work in your session store, and whether a non-browser client needs a different strategy. Passport authenticates a request; your API still needs its own permissions and owner-scoped data access.

Integration, limitations, and cost model: This is a composition project. You own registration, password recovery, account linking, cookie and CSRF policy, abuse controls, database storage, and TypeScript integration across the packages you select. The core middleware does not mount your application routes or prescribe a database schema. Estimate developer time and infrastructure alongside package selection, not just the price of a dependency. Choose Passport when control over your existing backend matters more than a packaged account-and-session workflow.

3. AdonisJS Auth: Guards inside an AdonisJS application

Screenshot of adonisjs.com

Best fit: A team already using AdonisJS, or intentionally choosing it for its integrated backend conventions. The AdonisJS authentication guide describes guards for cookie-backed sessions and opaque bearer access tokens, with providers responsible for user lookup and token verification. That makes the client decision concrete: browser sessions and API tokens are different transports, not interchangeable labels for the same flow.

Sessions and authorization: Pick the guard appropriate to your application, then protect routes explicitly. The guide notes that initialization middleware sets up the authenticator but does not itself authenticate every request or secure every endpoint. AdonisJS separates permissions into its Bouncer authorization system; a signed-in user still needs an action-specific and resource-specific policy. Check token expiry, session persistence, logout, and policy behavior in the exact starter and guard you deploy. The auth introduction describes these boundaries.

Integration, limitations, and cost model: AdonisJS Auth focuses on authenticating HTTP requests. Its documentation explicitly puts registration, email verification, password recovery, and account management outside the auth package's scope. You will implement or obtain those flows and own the database, email, hosting, and maintenance work. This option is less compelling if you do not want to adopt AdonisJS itself; choose it when your team values its application conventions as well as its auth guards.

4. db3.ai Auth: Sessions within a TypeScript application runtime

Screenshot of db3.ai

Best fit: A team that wants identity in the same application environment as data models, APIs, jobs, and AI features, while retaining control of public HTTP behavior. In db3.ai's Auth guide, UserIdentity is the account, AuthProvider attaches a login method, AuthToken represents a bearer session, and PasswordResetToken represents a recovery request. Password and configured Google login are documented; provider linking is explicit rather than silently merging accounts with matching emails.

Sessions and authorization: The auth service can issue, authenticate, list, and revoke bearer sessions. The consuming server chooses whether and how to carry a token in a cookie or another transport. In the starter's browser-to-database walkthrough, the HTTP application sets a host-only, HttpOnly cookie, authenticates it for protected routes, and durably revokes the current token at logout. The Auth guide also documents reset behavior that revokes sessions. Neither document says Auth automatically creates your login routes or grants record permissions.

Integration, limitations, and cost model: We would evaluate the starter as an implementation pattern, not mistake it for a complete hosted identity service. The application owns input validation, abuse controls, CSRF or origin policy, cookie configuration, recovery delivery, and authorization. The documented starter has password login; its Google button and credential-exchange route remain separate work. The package is described in the guide as a preview supplied through package tarballs, so confirm availability and commercial terms before planning a rollout. No published price is available in our product catalogue; do not infer that it costs nothing. Choose this route when ownership of app data, request context, and background work matters enough to justify implementing your public identity flows. The starter walkthrough distinguishes those pieces.

Prove authentication and authorization together

A useful proof of concept is a private note. After authenticating the session, the server must still constrain a lookup by both the requested ID and the authenticated owner. This excerpt follows the db3.ai owned-note guide; it is not a standalone route or a claim that we executed it here:

// Inside the generated starter's Fastify GET /api/notes/:id handler.
// The starter supplies application, request, Note, requireUser, and HttpError.
const user = await requireUser(application, request);
const note = await Note.where({ id: request.params.id, owner: user.id }).first();
if (!note) throw new HttpError(404, 'Note not found.');
return { note: note.toJSON() };

To run the full example, create the documented starter application, configure its SQL database and migrations, and use its existing cookie and route-validation setup. The snippet omits those application-specific pieces. requireUser is the starter's HTTP helper, not an automatically installed Auth route. In the starter, each HTTP request enters a request context before authentication; outside that context, do not assume current-user state is safely isolated across concurrent requests. The login walkthrough explains that boundary, and the Auth API reference documents the service operations.

Now test user A reading A's note, user B requesting A's note ID, and user A logging out before retrying. Repeat the policy test for updates, deletes, exports, and every background path. If the data belongs to an organization, replace simple owner equality with a policy that checks the trusted organization context and current membership; never accept an organization ID from the request as proof of access. OWASP's API1 guidance explains the object-level failure mode.

How to choose for multi-user and AI products

For a shortlist, run the same trial against two candidates: register or connect a user, sign in, reject a wrong credential, expire and revoke a session, change or reset a password, and deny a cross-user record lookup. Add a browser request and a programmatic client if you support both. Check typed APIs against the actual version you would install, including configuration, migrations, extension points, and executable consumer examples. A TypeScript type declaration does not validate an untrusted JSON body at runtime.

Then ask who owns each part of the product:

  • Need substantial auth features within an existing TypeScript stack? Evaluate Better Auth, including the database adapter, organization plugin, and the session configuration you will operate.
  • Need maximum choice in an established Express-compatible app? Evaluate Passport, but budget explicitly for your session store, registration and recovery flows, and authorization.
  • Already standardizing on AdonisJS? Test its guard and provider design alongside your application policies and account-management requirements.
  • Need authentication close to records, jobs, and agents? Trial db3.ai's Auth service and starter routes, then write your own resource policy and delivery flows.

An AI tool or queued job makes the separation sharper. A user can authorize a task at dispatch and lose access before the worker runs. Persist trusted user, tenant, and resource identifiers as application context, decide whether to recheck permission at execution, and fail safely if the policy no longer allows the action. Never let a model-supplied tool argument choose an unrestricted account or tenant; do not pass a browser session into a worker as though it were a durable service identity. This is an application design test, not a feature box in an auth product comparison.

Frequently asked questions

Does a TypeScript authentication framework also provide authorization?

Not necessarily. Some offer roles or policy helpers; none can infer the ownership rules for your particular records. Verify identity first, then authorize the action on the requested resource. OWASP's object-level guidance applies even when sign-in works correctly.

Should we use cookies or bearer tokens for sessions?

Start with your client and threat model, not the framework's default. A browser cookie needs deliberate cookie and cross-site request protections; an API bearer token needs secure client storage, bounded lifetime, and a tested revocation plan. Ask each candidate exactly where validation happens and what logout does. OWASP's session guidance provides the baseline questions.

Our recommendation

Choose the smallest operating model that actually covers your identity methods, session controls, and backend integration. We would prototype Better Auth first for a dedicated TypeScript auth layer, Passport for a deliberately composed existing server, AdonisJS Auth for an AdonisJS application, and db3.ai Auth for an application that needs auth alongside its records and jobs. Make the final choice only after both session revocation and cross-user denial pass in your own application.

If you are exploring the integrated route, start with the db3.ai authentication guide and the login-to-database walkthrough. Treat those as a starting implementation, then test your own tenant policies, recovery delivery, and worker permissions before shipping.

Sources