better-auth-plugins
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBetter Auth Plugins
Better Auth 插件系统
Goals
目标
- Add server plugins to extend auth features.
- Add client plugins for matching client methods.
- Apply schema changes when plugins add tables.
- 添加服务端插件以扩展认证功能。
- 添加对应的客户端插件以匹配服务端方法。
- 当插件添加数据表时应用架构变更。
Quick start
快速开始
- Import the plugin from and add it to
better-auth/plugins.plugins - Run migrations (or
generate) when required.migrate - Add the client plugin from .
better-auth/client/plugins
- 从导入插件并添加到
better-auth/plugins配置中。plugins - 必要时运行迁移命令(或
generate)。migrate - 从添加客户端插件。
better-auth/client/plugins
Example: Two-factor authentication
示例:双因素认证
ts
import { betterAuth } from "better-auth";
import { twoFactor } from "better-auth/plugins";
export const auth = betterAuth({
plugins: [twoFactor()],
});ts
import { createAuthClient } from "better-auth/client";
import { twoFactorClient } from "better-auth/client/plugins";
export const authClient = createAuthClient({
plugins: [twoFactorClient({ twoFactorPage: "/two-factor" })],
});ts
import { betterAuth } from "better-auth";
import { twoFactor } from "better-auth/plugins";
export const auth = betterAuth({
plugins: [twoFactor()],
});ts
import { createAuthClient } from "better-auth/client";
import { twoFactorClient } from "better-auth/client/plugins";
export const authClient = createAuthClient({
plugins: [twoFactorClient({ twoFactorPage: "/two-factor" })],
});Migration reminder
迁移提醒
Run the CLI when a plugin adds tables:
bash
npx @better-auth/cli generatebash
npx @better-auth/cli migrate当插件添加数据表时运行CLI命令:
bash
npx @better-auth/cli generatebash
npx @better-auth/cli migrateGuardrails
注意事项
- Add server and client plugins together to keep APIs aligned.
- Keep (if used) last in the server plugin list.
nextCookies - Review plugin docs for required schema and env variables.
- 同时添加服务端和客户端插件以保持API对齐。
- 如果使用,请将其放在服务端插件列表的最后。
nextCookies - 查看插件文档以了解所需的架构和环境变量。
References
参考资料
toolchains/platforms/auth/better-auth/better-auth-plugins/references/plugins-index.md
toolchains/platforms/auth/better-auth/better-auth-plugins/references/plugins-index.md