Better Auth
PackageOpen-source TypeScript authentication framework with a plugin system
- 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
- Run npm install better-auth
- Set BETTER_AUTH_SECRET and BETTER_AUTH_URL in your .env file
- 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.jsDetails
- Hosting
- Self-hosted, Runs locally
- Available in
- Worldwide
- Official SDKs
- JavaScript/TypeScript
- MCP server
- None
- Works with
- Postgres, MySQL, MongoDB