Repository navigation
fix(console): a link refused as already linked to another user, or as unable to link, says why where the signed-in person lands - #33585
Conversation
…igned-in person lands Co-Authored-By: Claude <noreply@anthropic.com>
|
domain:ui#1 · os-project-manager · session_01FEkQ5nWoa1Ze1QzjRTSYXD Contract reviewServed-tier: Inputs: card #33498 (body, claim 6887111102, os-dev-report 6887609141), PR #33585 body and its 14-file list, the net diff ① Derived judgments
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
domain:ui#1 · os-project-manager · session_01FEkQ5nWoa1Ze1QzjRTSYXD 席位核对Verdict: ACCEPT · head
|
|
domain:ui#1 · os-project-manager · session_01FEkQ5nWoa1Ze1QzjRTSYXD Landing · head
State: ready + auto-merge. |
…ectstack-ai#33679) <!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XSxY8jRG8MhDJB39LgakrUc)_ domain:ui#1 · os-project-manager · session_01FEkQ5nwxuShQ1A7T6jAiLn Fixes objectstack-ai#33650 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:组织邀请链路上的两个报错改成控制台自己的语言。打开失效的邀请链接时不再显示 better-auth 的英文 "Invitation not found!",而是「该邀请已被使用、已过期或已撤销。如果您已接受过该邀请,可在组织列表中找到该组织。」;邀请一个已经是成员的人时显示「该用户已是本组织成员。」。共 11 种语言。 - 为什么改:better-auth 的 `get-invitation` 对「找不到」只回 400 加一句英文,不带错误码,控制台按错误码翻译所以漏掉了;「已是成员」这个错误码也没有映射。已接受过的邀请再打开,服务端的回答和「找不到」完全一样,控制台无法区分,所以改为在同一句话里说明「可能已被使用」并指向组织列表(页面原有的「前往组织」按钮)。 - 风险与回滚:只认「`get-invitation` + 400 + 无错误码」这一种回答,不读英文原文;其他 400(带错误码的)和 401 等仍照旧显示服务端原句。`@object-ui/auth` 抛出的错误多带一个 `status` 字段,原有字段与文字不变。服务端不改。回滚即 revert 本 PR。 - 先看:`ui/packages/app-shell/src/console/organizations/orgErrorMessage.ts` 的 `resolveInvitationLookupMessage`;`ui/packages/auth/src/createAuthClient.ts` 的 `toAuthError` 一行;`ui/packages/i18n/src/locales/zh-Hans.ts` 的两句中文。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/console/organizations/__tests__/invitationVendorRefusals-33650.test.tsx`,预期 9 个用例全绿。 - 需要你做的:无,席位落地。 ## What changes - **The invitation lookup's code-less not-found reads as the console's sentence.** better-auth 1.7.12 `GET /organization/get-invitation` (`dist/plugins/organization/routes/crud-invites.mjs`, `getInvitation`) throws `APIError.fromStatus("BAD_REQUEST", { message: "Invitation not found!" })` with no `code` for an unknown id and for an invitation that is accepted, rejected, canceled or expired. Every other 400 the route answers names its code (`ORGANIZATION_NOT_FOUND`, `INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION`, better-call's `VALIDATION_ERROR`). The new `resolveInvitationLookupMessage` (orgErrorMessage.ts) reads exactly that answer, keyed on the route (only `AcceptInvitationPage`'s `getInvitation` catch calls it), status 400 and the missing code, and never on the English text (the module's rule, objectui#4474). Anything else goes through `resolveOrgErrorMessage` as before. - **`@object-ui/auth` carries the HTTP status.** `toAuthError` dropped `status`, so the page could not see the 400. It now copies a numeric `status` onto the thrown error, like the two-factor and invitation-preview errors in the same file already do. `message`, `code` and the rest are unchanged. `AuthClientError` is a module-internal type; no exported type changes. - **`USER_IS_ALREADY_A_MEMBER_OF_THIS_ORGANIZATION` joins `ORG_ERROR_MESSAGE_KEYS`** as `organization.errors.alreadyMember`, with a sentence in all 11 packs (10 hand-written, `zh-Hant` generated by `gen:zh-hant`). - **The not-found sentence names every state the server folds into it** ("already been used, has expired, or was revoked") and tells an invitee who accepted where the organization is. The error card already carries the "Go to organizations" button, which is the way in. ## Tests - `ui/packages/app-shell/src/console/organizations/__tests__/invitationVendorRefusals-33650.test.tsx` (new, 9 cases): the REAL `AcceptInvitationPage` and `InviteMemberDialog` under the real `I18nProvider`, with `useAuth` forwarding to the REAL `createAuthClient` over a stubbed `fetch` that answers better-auth 1.7.12's own bodies. Faces 1 (zh and en), 2 and 3, the pack census for the new key, and four CONTROLs: a coded 400 from get-invitation keeps its own message; a code-less 401 keeps its own message; `accept-invitation`'s coded `INVITATION_NOT_FOUND` still maps as before; an unmapped coded invite refusal keeps the server's sentence. - `ui/packages/auth/src/__tests__/authErrorStatus-33650.test.ts` (new, 2 cases): the real client carries `status` on a code-less and on a coded refusal, message unchanged. - `orgErrorMessage-4474.test.ts`: the mapping-table census names the new code. ## Acceptance notes - **Face 3 is worded, not detected.** The id alone cannot tell an accepted invitation from an unknown one: get-invitation refuses any status but `pending` with the same code-less 400, `list-user-invitations` filters to `pending`, and objectstack's signed-out `invitation-preview` answers one uniform 404 by design (ADR-0138 D2). The console could only find the invitation by listing invitations of every organization the user belongs to (`list-invitations` returns all statuses to a member), which is new fan-out fetching, not data the page already has, so the order's fallback applies: the sentence covers used / expired / revoked and points to the organization list. A server answer that tells a signed-in recipient "you already accepted this, organization X" is reported for a server card. - **Clause-② is `yes (widening)`** (seat reading, as for PR objectstack-ai#33485 and PR objectstack-ai#33585): `@object-ui/i18n` gains `organization.errors.alreadyMember` in all eleven locale packs (and rewords `organization.errors.invitationNotFound`), and errors thrown by `@object-ui/auth` gain a numeric `status` property beside `message` and `code`. Nothing is removed or narrowed; no exported type changes (`AuthClientError` is module-internal). - `resolveInvitationLookupMessage` is a separate entry point rather than a status rule inside `resolveOrgErrorMessage`: only the caller knows which route it called, and a code-less 400 from another organization route is not a not-found. ## Verification All local readings at head `2c555217` (the later head only changes the changeset's declaration line and prose; the changeset gates were rerun on it: check-changeset-no-major, check-empty-changeset, check-adr-0087-registration and its self-test, changeset-gate-self-tests, nul-bytes, all exit 0) (base `3c0033f9`; `origin/main` has moved 20 commits since, none touching these files). <details><summary>Measurement on base: all three faces reproduce</summary> Production sources put back to `3c0033f9` (tests kept), the new pins run, then `git checkout HEAD --` restored (`git diff HEAD` empty): ``` × getInvitation: the code-less not-found carries status 400 and no code (expected undefined to be 400) × inviteMember: a coded refusal carries its status beside the code × zh: draws the localized not-found sentence, not the vendor's English (Received: Invitation not found!) × en: draws the console's own English sentence, not the vendor's (Received: Invitation not found!) × reads as used / expired / revoked and points to the organization list (Received: "Invitation not found!") × zh: the invite dialog draws the localized sentence (Received: User is already a member of this organization) × organization.errors.alreadyMember is a translated string in each pack (en: undefined) Tests 7 failed | 4 passed (11) the 4 passing are the CONTROLs ``` Deciding lines on base: face 1 and 3, `orgErrorMessage.ts:191` (`resolveOrgErrorMessage` returns the non-empty message verbatim because the error has no code) behind `createAuthClient.ts:195` (`toAuthError` keeps `code`, drops `status`), called from `AcceptInvitationPage.tsx:84`; face 2, `ORG_ERROR_MESSAGE_KEYS` has no `USER_IS_ALREADY_A_MEMBER_OF_THIS_ORGANIZATION` row (invite section, `orgErrorMessage.ts:89-100`). Face 3 is the same wire answer as face 1: better-auth refuses any status but `pending` with the code-less 400. </details> <details><summary>Head: new pins and affected suites</summary> ``` pnpm exec vitest run invitationVendorRefusals-33650.test.tsx authErrorStatus-33650.test.ts Test Files 2 passed (2) · Tests 11 passed (11) pnpm exec vitest run packages/auth/ packages/i18n/ packages/app-shell/src/console/organizations/ packages/app-shell/src/console/auth/ apps/console/src/pages/auth/ first run: 1 failed | 2972 passed | 13 skipped (orgErrorMessage-4474 mapping-table census, which lists every mapped code); census updated in 2c55521 rerun of that file: Tests 21 passed (21) pnpm --filter @object-ui/auth run type-check :: exit 0 pnpm --filter @object-ui/app-shell run type-check :: exit 0 (tsc --noEmit and tsc -p tsconfig.test.json) pnpm --filter @object-ui/i18n run type-check :: exit 0 ``` </details> <details><summary>Ablations: each new branch, its pins red, restored to the HEAD blob</summary> `node scripts/ablation-replace.mjs` per leg (ui vitest reads these packages from source, so no dist leg): ``` A1 lookup branch off (guard forced false, marker ABL1) 3 failed: face 1 zh, face 1 en, face 3 A2 status narrowing off (any code-less answer reads not-found) 1 failed: CONTROL code-less 401 keeps its own message A3 toAuthError drops status (copy line forced off, marker ABL3) 5 failed: both auth pins, face 1 zh, face 1 en, face 3 A4 already-member row unkeyed (ABL4_USER_IS_ALREADY_A_MEMBER) 1 failed: face 2 zh each leg: "ok restored: blob == HEAD and `git diff HEAD` is empty" ``` The first A3 attempt was refused before running (anchor ambiguous, 2 hits, exit 3, nothing mutated); rerun with a three-line anchor. </details> <details><summary>Derived gates (39), dispatch-gates --ran: 39 derived, 39 run, 0 NOT-MEASURED</summary> ``` node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-sdui-manifest.mjs :: exit 0 node scripts/check-sdui-manifest.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --dir ui exec vitest run scripts/ :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:merge-driver :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:role-word :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 ``` </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (no spec change) - [x] 2. Every name I added uses the casing for its kind. - [ ] 3. No formatter ran; `pnpm lint` passes. (no formatter ran; `pnpm lint` was not run locally, the repo-wide lint run is CI's) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. (`.changeset/33650-invitation-refusal-copy.md`) - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. (the 维护者速读 block is the fleet's Chinese channel) --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5nwxuShQ1A7T6jAiLn)_ <!-- signed: domain:ui#1 · os-project-manager · session_01FEkQ5nWoa1Ze1QzjRTSYXD --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
Requested by Leehom · project thread
domain:ui#1 · os-project-manager · session_01FEkQ5oG4qX4LXsVnuxP2PZ
Fixes #33498
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
account_already_linked_to_different_user),或无法关联(unable_to_link_account,主要是不受信任的登录服务没有确认邮箱已验证)。这两种现在也走 Linking a social/OIDC account whose email doesn't match: the callback's error=email_does_not_match is never shown — the console bounces the signed-in user away #33063 的同一路径:用户落脚的页面弹出一条一直保留到关掉的错误提示,各有自己的句子,共 11 种语言(中文「该账号未关联:它已关联到本系统中的另一个用户…」「无法关联该账号。请确认它的邮箱地址已在该登录服务中完成验证…」)。SIGNED_IN_LINK_REFUSALS里加两条映射和两个文案键;只带错误码,URL 里的文字(包括error_description)一律不显示;提示里不出现其他用户或邮箱。服务端行为不变。回滚即 revert 本 PR。ui/apps/console/src/pages/auth/ssoCallbackRefusal.ts第 133–145 行的两条文案与第 171–175 行的映射;ui/packages/i18n/src/locales/zh-Hans.ts的两句中文。pnpm --dir ui exec vitest run apps/console/src/__tests__/App.linkRefusalLanding-33063.test.tsx,预期 12 个用例全绿(其中 console: linking a social/OIDC account that is already linked to another user, or that cannot be linked, still brings the signed-in person back with no word #33498 新增 8 个)。What changes
Measured live, through the real plugin-auth pipeline (
origin/maina9da547). Both codes are produced on the signed-in link path and land on the Console login page. A throwaway probe on theimplicit-account-linking.test.tsrig (a realAuthManagerover the in-memory engine, a stubbed generic-OAuth provider, a realPOST /api/v1/auth/link-social→GET /api/v1/auth/callback/acme-idpround trip with the signed-in cookie; not committed) read the callback'sLocation:probe: four signed-in links, the 302 each answered
Read on the vendor code (better-auth 1.7.12
oauth2/link-account.mjs,linkOAuthAccount): the email check runs first, soaccount_already_linked_to_different_useris reached only when the provider account's email equals the signed-in account's (orallowDifferentEmailsis on) andfindAccountByKeyanswers a row owned by another user;unable_to_link_accountis the untrusted-provider-and-unverified-email clause,accountLinking.enabled === false, or a failedcreateAccount. The callback (api/routes/callback.mjs) redirects both toonAPIError.errorURL, which plugin-auth sets to the Console login page, with noerror_description(the failure carries no message).ui/apps/console/src/pages/auth/ssoCallbackRefusal.ts: two copies,LINK_ALREADY_LINKED_TO_OTHER_USER(auth.login.errors.linkAlreadyLinkedToOtherUser) andLINK_UNABLE_TO_LINK(auth.login.errors.linkUnableToLink), and two entries inSIGNED_IN_LINK_REFUSALS. The doc comment names each code's producer. Nothing else changes: fix(console): a refused account link says why on the page the signed-in person lands on #33496'sholdLinkRefusalForLanding,LinkRefusalNotice,LoginPageandAppcarry them as they are.@object-ui/i18n: the two keys in all eleven locales (zh-Hant regenerated withgen:zh-hant). Each sentence says what happened and what to do, and names no other user or email..changeset/33498-link-refusal-other-codes-notice.md:@object-ui/consoleand@object-ui/i18npatch, both declaration lines.Not changed: the server, plugin-auth, better-auth.
Tests
ui/apps/console/src/__tests__/App.linkRefusalLanding-33063.test.tsxgains a#33498block through the same two-leg realApp(realLoginPageat the error URL, thenAppreopened where it sent the person, onlysessionStoragesurviving):account_already_linked_to_different_userandunable_to_link_account, each underenandzh-Hans: the toast reads that code's locale row exactly. The URL also carrieserror_description=bob@example.com already owns it, and the page text never containsbob@example.com.email_does_not_matchunderenandzh-Hansstill reads its own sentence, through the same table.?error=email_not_found(a vendor callback code that is not a link refusal) shows no notice and holds nothing. The existing<img>control is unchanged.Ablation (
scripts/ablation-replace.mjs --delete, anchor the two new map lines 1 → 0, blob071313cfbfc3→21dc9edf96a5; the console suite importssrc/, no dist in the path):Ablated: 4 failed | 8 passed (12); restored: blob == HEAD
Both
email_does_not_matchcontrols and the unknown-code control stay green with the entries gone.Acceptance notes
link-social→ callback path.account_already_linked_to_different_userwas staged by moving an existing account row to a second user in the store (the rig's posture refuses a second sign-up), which is the state the vendor branch reads.sys_accountunlink_account, viewmine), so the sentence says to sign in as the user it is linked to and unlink it there, or link a different account. Forunable_to_link_accountthe common cause a person can act on is an unverified email at the sign-in service; the rest (linking turned off, a failed write) is the administrator's, which the sentence names last.Verification
Head
06dc109b. Local subset fromnode scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack, reconciled with--ran:38 derived, 38 run, all exit 0; --ran: 0 NOT-MEASURED, 0 UNRUN
Also run locally on
06dc109b:pnpm --dir ui exec vitest run apps/console/src/pages/auth/ apps/console/src/__tests__/App.linkRefusalLanding-33063.test.tsx→ 35 files passed, 339 tests passed (VERDICT command-exit 0).pnpm --dir ui exec vitest run packages/i18n/→ 102 files passed, 1894 passed | 13 skipped (the i18n census pins included).pnpm --filter @object-ui/console --filter @object-ui/i18n run type-checkafter building the@object-ui/console^...closure → bothDone(the consoletsconfigincludessrc, so the new test is type-checked).eslintonssoCallbackRefusal.ts, the App test anden.ts→ exit 0;pnpm --dir ui check:new-line-citations→ 0 new.The full
@object-ui/consoleproject and every other family are CI's.Human Minimum
packages/specholds no runtime logic. (not touched)pnpm lintpasses. (touched files linted; the repo-wide run is CI's)main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed. (not touched)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01FEkQ5oG4qX4LXsVnuxP2PZ