{"id":18160,"library":"better-auth-typeorm-adapter","title":"Better Auth TypeORM Adapter","description":"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.","status":"active","version":"1.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/luratnieks/better-auth-typeorm-adapter","tags":["javascript","better-auth","typeorm","adapter","authentication","postgres","mysql","database","orm","typescript"],"install":[{"cmd":"npm install better-auth-typeorm-adapter","lang":"bash","label":"npm"},{"cmd":"yarn add better-auth-typeorm-adapter","lang":"bash","label":"yarn"},{"cmd":"pnpm add better-auth-typeorm-adapter","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: core authentication library this adapter implements interfaces for.","package":"better-auth","optional":false},{"reason":"Peer dependency: ORM used to define entities and perform database operations.","package":"typeorm","optional":false}],"imports":[{"note":"This is a named export, not default. CJS users: const { TypeORMAdapter } = require('better-auth-typeorm-adapter').","wrong":"import TypeORMAdapter from 'better-auth-typeorm-adapter'","symbol":"TypeORMAdapter","correct":"import { TypeORMAdapter } from 'better-auth-typeorm-adapter'"},{"note":"No default export exists. Always destructure the named export.","wrong":"const adapter = require('better-auth-typeorm-adapter')","symbol":"default","correct":"import { TypeORMAdapter } from 'better-auth-typeorm-adapter'"},{"note":"TypeScript declaration files for entities are re-exported from subpath 'entities'. Use type import for compile-time only.","wrong":"import { UserEntity } from 'better-auth-typeorm-adapter/entities'","symbol":"type UserEntity","correct":"import type { UserEntity } from 'better-auth-typeorm-adapter/entities'"},{"note":"Adapter options are not exported directly; infer from type parameter or use typeof.","wrong":"import { TypeORMAdapterOptions } from 'better-auth-typeorm-adapter'","symbol":"TypeORMAdapterOptions","correct":"import { TypeORMAdapter } from 'better-auth-typeorm-adapter'\nconst options: import('better-auth-typeorm-adapter').TypeORMAdapterOptions = { entities: [User, Account, Session, Verification] }"}],"quickstart":{"code":"import { DataSource } from 'typeorm';\nimport { TypeORMAdapter } from 'better-auth-typeorm-adapter';\nimport { betterAuth } from 'better-auth';\nimport { User } from './user.entity';\nimport { Account } from './account.entity';\nimport { Session } from './session.entity';\nimport { Verification } from './verification.entity';\n\nconst dataSource = new DataSource({\n  type: 'postgres',\n  url: process.env.DATABASE_URL ?? 'postgres://localhost:5432/mydb',\n  entities: [User, Account, Session, Verification],\n  synchronize: true,\n});\n\nawait dataSource.initialize();\n\nconst auth = betterAuth({\n  database: new TypeORMAdapter({\n    entities: {\n      user: User,\n      account: Account,\n      session: Session,\n      verification: Verification,\n    },\n    dataSource,\n  }),\n});","lang":"typescript","description":"Initialize TypeORM DataSource, define entities, create adapter, and pass to betterAuth."},"warnings":[{"fix":"Use the provided entity examples from the README and ensure column names match the default schema (email_verified, account_id, etc.).","message":"Entity schema must match Better Auth's expected fields exactly. Missing columns like 'emailVerified' (camelCase) or wrong column types cause runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to v1.1.4 and pass { entities, dataSource } object instead of separate arguments.","message":"Adapter v0.x used a different constructor signature. Version 1.x changed to receive a single options object.","severity":"deprecated","affected_versions":"<1.0.0"},{"fix":"Wrap entities in an object: new TypeORMAdapter({ entities: { user: User, ... }, dataSource }).","message":"TypeORMAdapter no longer accepts raw entity classes in an array; requires a mapping object with keys 'user', 'account', 'session', 'verification'.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use @PrimaryGeneratedColumn('uuid') on every entity's id column.","message":"All entity IDs must be UUIDs generated by TypeORM (e.g., @PrimaryGeneratedColumn('uuid')). Integer IDs will not satisfy Better Auth's internal checks.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set { debug: false } in options; default is false.","message":"Debug mode logs all adapter operations to stdout. Do not enable in production without a logger filter.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install peer deps: npm install better-auth@^1.3.0 typeorm@^0.3.0","cause":"Missing peer dependency (typeorm or better-auth) or incorrect import path.","error":"TypeError: Class extends value undefined is not a constructor or null"},{"fix":"Add explicit @Column({ name: 'email_verified' }) decorator with correct 'name' property.","cause":"Entity column name mismatch: TypeORM expects column names in snake_case (default naming strategy) but Better Auth provides camelCase.","error":"QueryFailedError: column \"email_verified\" does not exist"},{"fix":"Update to v1.1.4 and use import { UserEntity } from 'better-auth-typeorm-adapter' (no /entities subpath) or check type definitions.","cause":"Subpath exports not resolved; likely an old version of the adapter or incorrect path.","error":"Cannot find module 'better-auth-typeorm-adapter/entities'"},{"fix":"Pass { entities: {...}, dataSource: yourDataSource } as single argument.","cause":"TypeORMAdapter constructed without the 'dataSource' property in the options object.","error":"AuthError: Invalid adapter configuration: missing 'dataSource'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}