Better Auth TypeORM Adapter
raw JSON → 1.1.4 verified Sat Apr 25 auth: no javascript
A production-ready TypeORM adapter for Better Auth, the modern authentication library for TypeScript. Version 1.1.4 supports all Better Auth operations (CRUD, queries) with full type safety and multi-database compatibility (PostgreSQL, MySQL, SQLite). Requires peer dependencies better-auth ^1.3.0 and typeorm ^0.3.0. Zero runtime dependencies beyond peers, ships TypeScript types, includes debug mode for logging. Actively maintained with community contributions.
Common errors
error TypeError: Class extends value undefined is not a constructor or null ↓
cause Missing peer dependency (typeorm or better-auth) or incorrect import path.
fix
Install peer deps: npm install better-auth@^1.3.0 typeorm@^0.3.0
error QueryFailedError: column "email_verified" does not exist ↓
cause Entity column name mismatch: TypeORM expects column names in snake_case (default naming strategy) but Better Auth provides camelCase.
fix
Add explicit @Column({ name: 'email_verified' }) decorator with correct 'name' property.
error Cannot find module 'better-auth-typeorm-adapter/entities' ↓
cause Subpath exports not resolved; likely an old version of the adapter or incorrect path.
fix
Update to v1.1.4 and use import { UserEntity } from 'better-auth-typeorm-adapter' (no /entities subpath) or check type definitions.
error AuthError: Invalid adapter configuration: missing 'dataSource' ↓
cause TypeORMAdapter constructed without the 'dataSource' property in the options object.
fix
Pass { entities: {...}, dataSource: yourDataSource } as single argument.
Warnings
gotcha Entity schema must match Better Auth's expected fields exactly. Missing columns like 'emailVerified' (camelCase) or wrong column types cause runtime errors. ↓
fix Use the provided entity examples from the README and ensure column names match the default schema (email_verified, account_id, etc.).
deprecated Adapter v0.x used a different constructor signature. Version 1.x changed to receive a single options object. ↓
fix Upgrade to v1.1.4 and pass { entities, dataSource } object instead of separate arguments.
breaking TypeORMAdapter no longer accepts raw entity classes in an array; requires a mapping object with keys 'user', 'account', 'session', 'verification'. ↓
fix Wrap entities in an object: new TypeORMAdapter({ entities: { user: User, ... }, dataSource }).
gotcha All entity IDs must be UUIDs generated by TypeORM (e.g., @PrimaryGeneratedColumn('uuid')). Integer IDs will not satisfy Better Auth's internal checks. ↓
fix Use @PrimaryGeneratedColumn('uuid') on every entity's id column.
gotcha Debug mode logs all adapter operations to stdout. Do not enable in production without a logger filter. ↓
fix Set { debug: false } in options; default is false.
Install
npm install better-auth-typeorm-adapter yarn add better-auth-typeorm-adapter pnpm add better-auth-typeorm-adapter Imports
- TypeORMAdapter wrong
import TypeORMAdapter from 'better-auth-typeorm-adapter'correctimport { TypeORMAdapter } from 'better-auth-typeorm-adapter' - default wrong
const adapter = require('better-auth-typeorm-adapter')correctimport { TypeORMAdapter } from 'better-auth-typeorm-adapter' - type UserEntity wrong
import { UserEntity } from 'better-auth-typeorm-adapter/entities'correctimport type { UserEntity } from 'better-auth-typeorm-adapter/entities' - TypeORMAdapterOptions wrong
import { TypeORMAdapterOptions } from 'better-auth-typeorm-adapter'correctimport { TypeORMAdapter } from 'better-auth-typeorm-adapter' const options: import('better-auth-typeorm-adapter').TypeORMAdapterOptions = { entities: [User, Account, Session, Verification] }
Quickstart
import { DataSource } from 'typeorm';
import { TypeORMAdapter } from 'better-auth-typeorm-adapter';
import { betterAuth } from 'better-auth';
import { User } from './user.entity';
import { Account } from './account.entity';
import { Session } from './session.entity';
import { Verification } from './verification.entity';
const dataSource = new DataSource({
type: 'postgres',
url: process.env.DATABASE_URL ?? 'postgres://localhost:5432/mydb',
entities: [User, Account, Session, Verification],
synchronize: true,
});
await dataSource.initialize();
const auth = betterAuth({
database: new TypeORMAdapter({
entities: {
user: User,
account: Account,
session: Session,
verification: Verification,
},
dataSource,
}),
});