Better Auth is a comprehensive authentication framework designed for TypeScript applications, supporting various authentication methods like OAuth, OIDC, 2FA, and social logins. The current stable version is 1.6.5, with frequent patch and minor releases, alongside active beta development indicating continuous feature enhancements and bug fixes.
npm install better-authVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Better Auth in a TypeScript project using the Prisma adapter. It sets up the core `Auth` instance with a placeholder secret and hints at basic session retrieval in a server-side context.
Update calls to `enableTwoFactor` to provide the `method` parameter and handle the new discriminated return type. Ensure `otpOptions.sendOTP` is configured for OTP method.
Add a `verified` column to your `twoFactor` database table. Regenerate and apply your ORM migration (e.g., `npx prisma migrate dev` for Prisma or `npx drizzle-kit push` for Drizzle) and then `npx auth@latest generate`.
Review any custom logic relying on `session.freshAge`. If you need to disable the fresh session check entirely, set `session: { freshAge: 0 }` in your Auth configuration.This issue was fixed in `v1.7.0-beta.1` and later to apply 2FA across all sign-in paths. Upgrade to the latest stable version or a `v1.7.0-beta.x` release if comprehensive 2FA enforcement is required.
Run `npx auth@latest generate` to update your ORM client, then apply the schema migration using your ORM's command (e.g., `npx prisma migrate dev` or `npx drizzle-kit push`).
Define the `AUTH_SECRET` environment variable in your application's environment (e.g., `.env` file) with a long, randomly generated string. Do not hardcode secrets in your codebase.
Ensure `auth` is properly instantiated and exported. When calling `getSession` server-side, pass the relevant request object, e.g., `await auth.getSession({ req })`.Update your `enableTwoFactor` calls to explicitly specify the `method` as either `'otp'` or `'totp'`, e.g., `auth.enableTwoFactor({ method: 'totp' })`.No dependency data recorded yet.