{"library":"mikro-orm-better-auth","title":"MikroORM Better Auth Adapter","description":"mikro-orm-better-auth is an adapter for the 'better-auth' authentication library, specifically designed to integrate with MikroORM. It provides a robust database layer for better-auth, abstracting common CRUD operations and transactional support through MikroORM's `EntityManager`. A key differentiator is its `createSchema` implementation, which leverages `ts-morph` to generate MikroORM entity files automatically. These generated entities are intelligently patched in-place on regeneration, preserving user-owned code like custom imports, decorators, methods, and comments, while only updating generator-managed fields and decorators. The current stable version is 1.1.1, released in March 2026, indicating active development with a focus on stability and feature enhancements. It is primarily SQL-oriented, utilizing MikroORM's SQL entity manager, and defers native join support for future development.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install mikro-orm-better-auth"],"cli":null},"imports":["import { mikroOrmAdapter } from 'mikro-orm-better-auth';","import { betterAuth } from 'better-auth';","import { RequestContext } from '@mikro-orm/core';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { betterAuth } from 'better-auth';\nimport { mikroOrmAdapter } from 'mikro-orm-better-auth';\nimport { MikroORM, RequestContext } from '@mikro-orm/core';\nimport { SqliteDriver, SqlEntityManager } from '@mikro-orm/sqlite';\n\nasync function bootstrap() {\n  const orm = await MikroORM.init<SqliteDriver>({\n    driver: SqliteDriver,\n    dbName: 'app.sqlite',\n    entities: [], // Mikro-orm-better-auth generates entities, so leave this empty initially or add manually\n  });\n\n  // For per-request EntityManager isolation (recommended in web servers)\n  const auth = betterAuth({\n    database: mikroOrmAdapter(() => RequestContext.getEntityManager()! as SqlEntityManager),\n  });\n\n  // Example of generating entities\n  const adapter = mikroOrmAdapter(() => orm.em, {\n    generateEntity: {\n      outputDir: 'src/auth/entities', // Output directory for generated MikroORM entities\n    },\n  });\n\n  // In a real application, you would pass the adapter to betterAuth and then call auth methods.\n  // This snippet focuses on setup and entity generation.\n  console.log('MikroORM initialized and adapter configured. Entities will be generated to src/auth/entities.');\n}\n\nbootstrap().catch(console.error);","lang":"typescript","description":"Demonstrates the basic setup of `mikro-orm-better-auth` with MikroORM, including `RequestContext` for per-request EntityManager isolation and configuring entity generation.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}