Better Auth

Package

Open-source TypeScript authentication framework with a plugin system

Price
Free, open source; paid cloud plans
Access
None, runs in your app

About

MIT-licensed TypeScript auth library that runs inside your own server and database, with email and password, social sign-on and plugins for 2FA, passkeys, organizations and SSO. The optional paid Better Auth Infrastructure adds a dashboard, audit logs and abuse protection.

What you can do with it

  • Add email and password and social sign-in to a Next.js, Nuxt or SvelteKit app
  • Keep users and sessions in your own Postgres, MySQL, SQLite or MongoDB database
  • Add 2FA, passkeys, organizations and SAML SSO through plugins

Get started

  1. Run npm install better-auth
  2. Set BETTER_AUTH_SECRET and BETTER_AUTH_URL in your .env file
  3. Run npx auth@latest migrate to create the database tables

Example

// auth.ts
import { betterAuth } from "better-auth";
import Database from "better-sqlite3";

export const auth = betterAuth({
  database: new Database("./sqlite.db"),
  emailAndPassword: { enabled: true },
});
// Mount auth.handler on /api/auth/*, e.g. toNextJsHandler(auth) in Next.js

Details

Hosting
Self-hosted, Runs locally
Available in
Worldwide
Official SDKs
JavaScript/TypeScript
MCP server
None
Works with
Postgres, MySQL, MongoDB

Tasks

Alternatives

Other tools for the same tasks.

Last checked on .