@forklaunch/better-auth-mikro-orm-fork

中文文档
0.5.12发布于 2026/10/14MITTypeScriptES Module近 30 天下载 3401

Mikro ORM Adapter for Better Auth

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. API
  4. mikroOrmAdapter(orm: MikroORM): AdapterInstance
  5. Application operation context

better-auth-mikro-orm

MikroORM adapter for Better Auth

CI codecov

Installation

Using npm:

npm i better-auth-mikro-orm

Using yarn:

yarn add better-auth-mikro-orm

Using pnpm:

pnpm add better-auth-mikro-orm

Usage

  1. First you'll need to set up MikroORM and define the core schema for Better Auth. If you use any plugin, don't forget to check if they have any additional database schema definitions, then define entities you'll need for each plugin.
  2. When you're finished with the schema definitions, you can simply pass the result of the mikroOrmAdapter call to the database option like this:
import { mikroOrmAdapter } from "better-auth-mikro-orm";
import { betterAuth } from "better-auth";

import { orm } from "./orm.js"; // Your Mikro ORM instance

export const auth = betterAuth({
  database: mikroOrmAdapter(orm),

  // Don't forget to disable the ID generator if it is already managed by MikroORM
  advanced: {
    database: {
      generateId: false,
    },
  },
});

API

mikroOrmAdapter(orm: MikroORM): AdapterInstance

Creates the MikroORM adapter instance. Note that this adapter does not manage database schemas for you, so you can't use it with @better-auth/cli. This means you'll have to manage database schemas on your own. Please refer to the Better Auth and MikroORM documentations for details.

Returns the AdapterInstance function for the Better Auth database option.

This function expects a single argument:

  • orm - An instance of MikroORM returned from either MikroORM.init or MikroORM.initSync.

Application operation context

Applications with encrypted database fields can supply operationContext to mikroOrmAdapter. It runs around every adapter operation (including output normalization) and the entire transaction, including its final flush. This also covers direct auth.api calls without an HTTP middleware wrapper.

mikroOrmAdapter(orm, {
  operationContext: operation => trustedEncryptionScope.run(appKey, operation)
})

The adapter does not choose an encryption key or tenant, import an encryption library, reinterpret existing ciphertext, or supply a fallback context. The application must choose its trusted scope. An identity shared across organizations usually needs an explicit application-owned identity policy rather than the currently selected business organization. Changing an existing policy requires a separately reviewed ciphertext migration. Omitting this option preserves existing adapter behavior. Do not use request body fields to choose an encryption scope.

版本与发布记录

@forklaunch/better-auth-mikro-orm-fork 共发布 22 个版本,首次发布于 2025/06/08;过去 12 个月发布了 13 个版本。

版本发布日期距今
0.5.12latest2026/10/141 个月前
0.5.112026/10/091 个月前
0.5.102026/10/021 个月前
0.5.92026/08/282 个月前
0.5.82026/08/282 个月前
0.5.72026/08/202 个月前

关于 @forklaunch/better-auth-mikro-orm-fork 的常见问题

@forklaunch/better-auth-mikro-orm-fork 是什么?

Mikro ORM Adapter for Better Auth

如何安装 @forklaunch/better-auth-mikro-orm-fork?

在项目目录运行 npm install @forklaunch/better-auth-mikro-orm-fork,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:better-auth(^1.6.0)、@mikro-orm/core(^7.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@forklaunch/better-auth-mikro-orm-fork 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@forklaunch/better-auth-mikro-orm-fork 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@forklaunch/better-auth-mikro-orm-fork 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@forklaunch/better-auth-mikro-orm-fork 可以商用吗?

@forklaunch/better-auth-mikro-orm-fork 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@forklaunch/better-auth-mikro-orm-fork 的下载量有多少?

根据 npm 官方下载统计,@forklaunch/better-auth-mikro-orm-fork 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,401 次,日均约 113 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@forklaunch/better-auth-mikro-orm-fork 还在维护吗?

最新版本 0.5.12 发布于 2026/10/14(1 个月前);至今共发布 22 个版本,其中过去 12 个月发布了 13 个;首次发布于 2025/06/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。