关于 better-auth-plugins
better-auth-plugins 是用于扩展 Better Auth 身份验证功能的技能,面向配置服务端与客户端插件的开发者。它说明插件配对、所需数据库迁移及配置注意事项。
主要功能
- 01配置服务端插件
- 02添加匹配的客户端插件
- 03生成或执行迁移
- 04提供插件配置注意事项
适用场景
- 01为应用添加双因素认证
- 02同步服务端与客户端认证 API
- 03为插件新增表执行迁移
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ bobmatnyc/ claude-mpm-skills --skill better-auth-plugins安装后在 Claude Code 中输入/better-auth-plugins确认已加载。
附带文件metadata.jsonreferences/plugins-index.md
详细介绍
Better Auth 插件
目标
- 添加服务端插件以扩展身份验证功能。
- 添加与之匹配的客户端插件方法。
- 当插件添加表时应用架构变更。
快速开始
- 从
better-auth/plugins导入插件,并将其添加到plugins。 - 需要时运行迁移(
generate或migrate)。 - 从
better-auth/client/plugins添加客户端插件。
示例:双因素身份验证
import { betterAuth } from "better-auth";
import { twoFactor } from "better-auth/plugins";
export const auth = betterAuth({
plugins: [twoFactor()],
});
import { createAuthClient } from "better-auth/client";
import { twoFactorClient } from "better-auth/client/plugins";
export const authClient = createAuthClient({
plugins: [twoFactorClient({ twoFactorPage: "/two-factor" })],
});
迁移提醒
当插件添加表时,运行 CLI:
npx @better-auth/cli generate
npx @better-auth/cli migrate
注意事项
- 同时添加服务端和客户端插件,以保持 API 一致。
- 如果使用
nextCookies,请将其放在服务端插件列表的最后。 - 查看插件文档,了解所需的架构和环境变量。
参考资料
toolchains/platforms/auth/better-auth/better-auth-plugins/references/plugins-index.md
评论
支持 Markdown