This package provides a Mikro ORM adapter for Better Auth, allowing developers to integrate Better Auth's authentication functionalities with a MikroORM-managed database. The current stable version is `0.5.0`, and the project demonstrates a relatively active release cadence with frequent minor and patch updates based on the provided changelog. A key differentiator is its specific integration with MikroORM, serving as a bridge for authentication operations. It's crucial to note that this adapter does not handle database schema management directly; users are expected to define and manage their core Better Auth and plugin-specific schemas within MikroORM independently. This also means it cannot be used with `@better-auth/cli` for schema generation or migrations, distinguishing it from adapters that abstract schema concerns.
npm install better-auth-mikro-ormVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Better Auth using the `better-auth-mikro-orm` adapter, passing a MikroORM instance and disabling Better Auth's default ID generator.
For `updateMany` operations, be aware that the Identity Map will not reflect changes. Manual `em.clear()` or `em.refresh()` might be necessary for affected entities if up-to-date Identity Map state is required immediately after `updateMany`.
Manually define MikroORM entities for Better Auth's core schema and any plugins. Use MikroORM's migration system (e.g., `mikro-orm migration:create`, `mikro-orm migration:up`) to manage your database schema.
Add `advanced: { database: { generateId: false } }` to your `betterAuth` configuration object to prevent conflicts with MikroORM's ID generation strategy.Ensure your MikroORM instance is fully initialized before passing it to `mikroOrmAdapter`. For example: `const orm = await MikroORM.init(config);` then `mikroOrmAdapter(orm)`.
Ensure you are using `import { mikroOrmAdapter } from 'better-auth-mikro-orm';` for ESM. Verify `"type": "module"` is set in your `package.json` if using ESM. Check that the package is correctly installed.Verify that `MikroORM.init()` or `MikroORM.initSync()` successfully completes and returns a valid `MikroORM` instance before passing it to `mikroOrmAdapter`. Await the initialization call if it's asynchronous.
Add or verify `advanced: { database: { generateId: false } }` in your `betterAuth` configuration. Ensure your MikroORM entities have appropriate primary key strategies (e.g., `uuid` or `serial`).