ENATIV Logo
ENATIV
Back
© 2026 ENATIV
ProjectsServicesKnowledge hubContact
contact@enativ.pl
  1. Knowledge hub
  2. ›
  3. Backend & APIs
  4. ›
  5. Better Auth

Better Auth

A TypeScript sign-in library: users and sessions live in your own app database, not with a vendor.

Backend & APIsUsing since 2024 · Featured project: The Travelling Cows

Category
Backend & APIs
Using since
2024
Featured project
The Travelling Cows

In practice

I pick Better Auth when sign-in should live in the app code and the users in the app database, not with an outside provider. At The Travelling Cows it handles Google sign-in on a trip booking platform built in Next.js.

What is Better Auth?

Better Auth is a framework-agnostic authentication and authorization library for TypeScript. Password sign-in, social accounts, sessions, rate limiting and database migrations come built in, and advanced features such as two-factor sign-in or multi-tenancy arrive as plugins.

It runs inside your app, so users, accounts and sessions land in a database connected through an adapter, such as PostgreSQL. A session is an ordinary cookie that expires after seven days by default.

License
MIT
Language
TypeScript
User data
In your own database
Sessions
A cookie, seven days by default

How I work with Better Auth

I start by asking who signs in and how. That decides whether a Google account is enough, or whether passwords and sessions on several devices are needed too.

  1. Schema and adapter

    I connect an adapter to the project database and generate the schema with the CLI, so the user and session tables join the other migrations of the project.

  2. Sign-in providers

    I configure only the providers the project needs. On The Travelling Cows that is a Google account. It needs OAuth credentials from the Google console, which go into the config.

  3. Sessions and access

    I set session lifetime and refresh to fit the project. I check access to routes on the server in Next.js, not only in the interface, which is easy to bypass.

When it fits, and when it doesn't

Better Auth fits where sign-in is part of the app, not a separate service.

A good fit when

  • A Next.js app where the users should sit in your own database.
  • Google sign-in and, when needed, a password as well.
  • A project where user data has to stay under your control.
  • A team that will keep the config in code and review it like any other change.

Not a fit when

  • A mobile app that already runs entirely on Firebase services.
  • A team where nobody will look after the database or library updates.
  • An editor panel that is fine with the account built into the CMS.
  • A company with a ready central sign-in system that has to stay.

For a mobile app on Firebase I stay with Firebase Auth, and for an editor panel the sign-in from Payload CMS is enough.

Better Auth or Firebase Auth?

Both handle sign-in, but in different places. They differ in who holds the users and how far the dependence on a vendor reaches.

Better Auth and Firebase Auth compared
CriterionBetter AuthFirebase
Where users liveIn the app databaseIn a Google-hosted service
SessionsA cookie, seven days by defaultAn ID token for an hour, refreshed
Provider setupIn the project codeIn the Firebase console or CLI
Vendor dependenceCode and data are yoursAccounts and tokens stay in Firebase
Cost modelFree library, you pay for hostingFree plan, then pay by usage
Platform couplingIndependent of framework and hostTightly tied to Firebase services

Choose Better Auth when

you want users in your own database and sign-in in code you maintain anyway. You pay with time for configuration and updates that nobody else will do for you.

Choose Firebase Auth when

the mobile app already runs on Firebase and should work without a server of its own. You get a ready SDK and a hosted service, but the user accounts stay with Google.

On The Travelling Cows I used Better Auth for Google sign-in.

Frequently asked questions

The code is open and MIT-licensed, so you run it inside your own app. You pay for hosting with a database and for the time spent on configuration, not for the library itself.
In the database you connect through an adapter. The library keeps users and sessions there, and a CLI command creates the schema. If you change hosts, you move the database with the whole app, with no separate sign-in service to rewire.
You can, but it is work for every user, not a switch. Firebase keeps accounts and sessions on its side, so before a change I settle what has to move and how people sign in the first time on the new system.
Yes, through plugins. Two-factor sign-in and passkeys are among them. I add them only when the project needs them, because a plugin can bring its own database tables, and every table is one more thing to maintain.

On this page

  • In practice
  • What is Better Auth?
  • How I work with Better Auth
  • When it fits, and when it doesn't
  • Better Auth or Firebase Auth?
  • Frequently asked questions

Related topics

  • Better Auth
  • Next.js
  • Firebase
  • Payload CMS
  • TypeScript

Want to straighten out sign-in in your app?

Describe who has to sign in and whether the user data should stay with you. I will answer whether Better Auth fits, or whether a hosted provider is the better pick.

Describe your projectSee The Travelling Cows