Skip to content

feat: adapt better-auth adapter and objects for sys_ prefix naming convention - #745

Merged
hotlong merged 3 commits into
mainfrom
copilot/adapt-better-auth-sys-prefix
Feb 19, 2026
Merged

hotlong merged 3 commits into
mainfrom
copilot/adapt-better-auth-sys-prefix

Conversation

Copilot AI commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

better-auth hardcodes model names (user, session, account, verification) but the protocol layer now requires sys_ prefixed names. The adapter layer couldn't resolve the correct object definitions, breaking auth flows.

Adapter mapping (objectql-adapter.ts)

  • Added AUTH_MODEL_TO_PROTOCOL mapping and resolveProtocolName() to translate better-auth model names → protocol names
  • All 8 adapter operations now route through resolveProtocolName(model) instead of passing raw model names
  • Unknown models pass through unchanged for extensibility (e.g. better-auth plugins adding custom models)
import { AUTH_MODEL_TO_PROTOCOL, resolveProtocolName } from '@objectstack/plugin-auth';

// { user: 'sys_user', session: 'sys_session', account: 'sys_account', verification: 'sys_verification' }
resolveProtocolName('user');    // → 'sys_user'
resolveProtocolName('custom');  // → 'custom' (passthrough)

Object definitions

  • auth-user.object.ts → name: 'sys_user'
  • auth-session.object.ts → name: 'sys_session'
  • auth-account.object.ts → name: 'sys_account'
  • auth-verification.object.ts → name: 'sys_verification'

Tests

  • 11 new tests covering mapping constants, resolveProtocolName fallback, and all adapter operations confirming sys_ names reach IDataEngine

Documentation

  • Updated plugin-auth README.md, authentication.mdx, and ROADMAP.md migration notes

Breaking change: Custom adapters or plugins referencing auth objects by name must switch to sys_-prefixed protocol names (or import SystemObjectName constants). Client-side REST routes (/api/v1/auth/*) are unaffected.

Original prompt

This section details on the original issue you should resolve

<issue_title>better-auth适配内核 sys_ 前缀命名和协议表名映射,前端API兼容评估</issue_title>
<issue_description>## 背景
近期已将系统内核对象的协议层命名全部统一为 sys_ 前缀(详见 #738),但 better-auth 深度集成需要兼容这一变更。

影响分析

better-auth 核心对象名是硬编码的('user'、'session'、'account'、'verification'),而现在协议层为 'sys_user'、'sys_session' ...。此时:

  • better-auth -> ObjectQL adapter 层调用时依赖 model = 'user'(等四个核心对象名)
  • Auth 对象定义、系统协议层常量已切换为 'sys_user' 等

现状会导致 adapter 层找不到正确 object definition,影响认证流程。

客户端 API 仅通过 HTTP REST 路由(/auth/sign-in, /auth/get-session 等)访问,不直接涉及对象名,前端接口无影响。但如果直接操作对象(如 client.data.find('user', ...)),需要同步切换新协议名。

必须修正内容

  1. adapter(model名到协议object名的映射)
    • 在 objectql-adapter.ts 增加 model→protocol name 映射,如:{"user":"sys_user",...}
    • 所有 adapter 函数通过映射表查找 object definition
  2. auth对象四个定义文件同步name值
    • auth-user.object.ts:name: 'sys_user'
    • auth-session.object.ts:name: 'sys_session'
    • auth-account.object.ts:name: 'sys_account'
    • auth-verification.object.ts:name: 'sys_verification'
  3. 配套文档集中更新
    • README、authentication.mdx
    • 补充说明"better-auth对象映射适配"原理、升级影响

ROADMAP动作建议


涉及 breaking change,需团队评审通过。</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel

vercel Bot commented Feb 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-play Error Error Feb 19, 2026 3:47pm
spec Error Error Feb 19, 2026 3:47pm

Request Review

…nvention

- Add AUTH_MODEL_TO_PROTOCOL mapping and resolveProtocolName() in objectql-adapter.ts
- Update all auth object definitions to use sys_ prefixed names (sys_user, sys_session, sys_account, sys_verification)
- Add comprehensive adapter mapping tests (11 tests)

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
…x adaptation

- Update plugin-auth README.md with sys_ prefixed object names and adapter mapping docs
- Update authentication.mdx guide with protocol name mapping explanation
- Update ROADMAP.md migration notes for better-auth adapter

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Adapt better-auth for sys_ prefix naming and mapping feat: adapt better-auth adapter and objects for sys_ prefix naming convention Feb 19, 2026
Copilot AI requested a review from hotlong February 19, 2026 15:48
@hotlong
hotlong marked this pull request as ready for review February 19, 2026 18:37
Copilot AI review requested due to automatic review settings February 19, 2026 18:37
@hotlong
hotlong merged commit 4b6cf91 into main Feb 19, 2026
1 of 3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adapts the @objectstack/plugin-auth to align with the new sys_ prefix naming convention for system kernel objects (issue #738). The change bridges the gap between better-auth's hardcoded model names (user, session, account, verification) and ObjectStack's protocol-layer naming convention that requires sys_ prefixes for system objects.

Changes:

  • Introduced AUTH_MODEL_TO_PROTOCOL mapping and resolveProtocolName() function to translate better-auth model names to protocol names
  • Updated all four auth object definitions to use sys_ prefixed names
  • Added comprehensive test coverage for the mapping layer and adapter operations
  • Updated documentation (README, authentication.mdx, ROADMAP) to explain the adapter mapping pattern

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/plugins/plugin-auth/src/objects/auth-user.object.ts Updated object name from user to sys_user
packages/plugins/plugin-auth/src/objects/auth-session.object.ts Updated object name from session to sys_session
packages/plugins/plugin-auth/src/objects/auth-account.object.ts Updated object name from account to sys_account
packages/plugins/plugin-auth/src/objects/auth-verification.object.ts Updated object name from verification to sys_verification
packages/plugins/plugin-auth/src/objectql-adapter.ts Added AUTH_MODEL_TO_PROTOCOL mapping and resolveProtocolName() function; updated all 8 adapter operations to use the mapping
packages/plugins/plugin-auth/src/objectql-adapter.test.ts Added 11 new tests covering mapping constants, resolver fallback, and adapter operations
packages/plugins/plugin-auth/README.md Updated documentation to explain the model-to-protocol name mapping pattern
content/docs/guides/authentication.mdx Updated guide with sys_ prefix convention and upgrade notes
ROADMAP.md Added migration note about AUTH_MODEL_TO_PROTOCOL mapping requirement

Comment on lines +108 to +112
it('should pass through unknown model names unchanged', async () => {
const adapter = createObjectQLAdapter(mockEngine);
await adapter.create({ model: 'organization', data: { name: 'Acme' } });
expect(mockEngine.insert).toHaveBeenCalledWith('organization', { name: 'Acme' });
});

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite is missing coverage for updateMany and deleteMany adapter operations. While the implementation correctly uses resolveProtocolName() in both operations (lines 148 and 185 of objectql-adapter.ts), there are no tests to verify that these operations properly map model names to protocol names. Consider adding test cases similar to the existing ones for these two operations to ensure complete adapter coverage.

Copilot uses AI. Check for mistakes.

This branch had an error being deployed

2 failed deployments
Preview – spec — 0cca9541 Deployed Feb 19, 2026 by vercel[bot]
Preview – objectstack-play — 0cca9541 Deployed Feb 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

better-auth适配内核 sys_ 前缀命名和协议表名映射,前端API兼容评估

3 participants