Skip to content

feat(auth): 支持用户名/工号登录 —— 接入 better-auth username 插件 #2756

Description

@baozhoutao

诉求

接入 better-auth 的 username 插件,支持用户名登录(/api/v1/auth/sign-in/username,可用用户名或邮箱登录)。

现状

plugin-auth 目前没接 username(),登录标识符只有邮箱(见 packages/plugins/plugin-auth/src/auth-manager.ts 的 buildPluginList())。而 better-auth@1.6.23 内置就有 username 插件(支持 displayUsername、isUsernameAvailable 查重),原生可用。

做法

  1. auth-manager.ts 里 plugins.push(username({ schema: ... })),加 feature flag 门控(对齐现有 enabled.xxx 约定)。
  2. Schema 迁移:user 表加 username / display_username 列,snake_case 映射(参考现有 buildAdminPluginSchema())。
  3. 暴露到 /api/v1/auth/config 的 features,前端登录页据此支持"用户名或邮箱"输入(objectui 侧配合)。

属于改框架代码 + 迁移,非配置开关。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions