Repository navigation
Commit c4c0794
fix(plugin-auth,app-shell)!: while mail is live, accepting an invitation needs a verified address (#34666)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9R6fQuMSzSrRW2oowG4K2kQ)_
Fixes #34272
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no page under `skills/` teaches accepting an
invitation or `/organization/accept-invitation`; the rule is stated in
the changeset and the self-hosting docs.
> **Governed / Tier H.** A narrowing of an auth route (BREAKING). This
PR stays **draft** until `GOVERNED_APPROVERS` approve; the seat lands it
through Tier H. The area thread does not flip it ready.
## 维护者速读
- **改了什么**:邮件服务可投递(`isConfigured() === true`)时,`POST
/organization/accept-invitation` 拒收邮箱未验证的会话:`403
EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION`(better-auth
自己的码与句子),什么都不写,邀请仍是 pending。控制台接受页把这个拒绝转到
`/verify-email-prompt`(发验证邮件),验证链接带回接受页。
- **为什么改**:规则是邮件可投递时,接受邀请需要已验证的邮箱,因为未验证的地址不能证明持有受邀邮箱。
- **范围(席位收窄后)**:只动
accept;`get-invitation`、`list-user-invitations`、`reject-invitation`
不变(不写成员);一步接受门不变(凭证模式先验证再接受,会话模式本来就答
`verify_email`);**没有可投递邮件的部署完全不变**(那里什么都无法验证地址,拒收等于死路,也是
`requireEmailVerificationOnInvitation: false` 的原因,该声明保留)。
- **风险与回滚**:BREAKING 只落在「邮件可投递 + 未验证地址的人去接受」这一种人身上,修法是先验证邮箱。回滚即还原本
PR:接线只有 `auth-manager-organization-plugin.ts` 里一个
`beforeAcceptInvitation` 钩子 + 两处宿主成员透传。
-
**先看**:`packages/plugins/plugin-auth/src/invitation-accept-verified-email.ts`(规则与为何选
vendor 钩子);`auth-manager-organization-plugin.ts` 的
`beforeAcceptInvitation`;`ui/.../AcceptInvitationPage.tsx` 的
`handleAccept`。
- **两分钟验证**:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/invitation-accept-verified-email.test.ts`,预期 14 个用例全绿。
- **需要你做的**:作为受管(Tier H)收窄,按 GOVERNED_APPROVERS 批准;其余席位落地。
## What changes
**Rule.** While the deployment's mail transport is live, an invitation
is accepted only by a session whose address is verified. Without a live
transport nothing changes.
- `packages/plugins/plugin-auth/src/invitation-accept-verified-email.ts`
(new): `refuseUnverifiedAcceptWhileMailIsLive(user, {
isEmailDeliveryLive, verificationRequired? })`, a no-op for a verified
user (it does not even ask whether mail is live) and while mail is not
live; otherwise it throws `APIError.from('FORBIDDEN', …)` with the
vendor's own `$ERROR_CODES` entry (a local fallback is pinned equal to
the vendor's). The verified test is the vendor's own
(`!user.emailVerified`).
- `auth-manager-organization-plugin.ts`: the rule is asked from
better-auth's `organizationHooks.beforeAcceptInvitation`, which the
vendor fires inside the accept endpoint after its not-found / expiry /
status, recipient and membership-limit checks and before the invitation
row or the membership is written, handing it the `session.user` its own
session middleware resolved (cookie and bearer alike). The
`requireEmailVerificationOnInvitation: false` comment now says why it
stays false and where the live-mail rule lives.
- `auth-manager.ts`, `auth-manager-plugin-list.ts`:
`isEmailDeliveryLive` passed through the two typed hosts to the
organization plugin.
- `ui/packages/app-shell/.../AcceptInvitationPage.tsx`: on that code,
navigate to `/verify-email-prompt?email=<account email>&redirect=<this
page>` instead of a toast. `orgErrorMessage.ts` exports the code and
`isAcceptNeedsVerifiedEmail(err)` (read by code only).
- `content/docs/deployment/self-hosting.mdx`: one paragraph under the
`invite_only` sign-up paragraph.
- `packages/runtime/src/dispatcher-error-vocabulary.ts`: one
`foreign-vocabulary` row classifying the vendor code, beside the sibling
row for `EMAIL_VERIFICATION_REQUIRED_FOR_INVITATION`
(`check:dispatcher-error-vocabulary`).
- `.changeset/34272-accept-invitation-verified-email.md`:
`@objectstack/plugin-auth`, `@object-ui/app-shell` and
`@objectstack/runtime` patch (`Metadata-protocol: none` takes patch; the
BREAKING banner stays); BREAKING, Who moves, `adr-0087: not-required
(no-migration-prescription)`.
No spec, schema, stored row, route or exported signature of a published
entry changes. No new error code is minted (the vendor's), so nothing
reaches the error-code ledger.
### Why the vendor hook and not the global before-hook
The seat's correction named "a plugin-auth before-hook".
`beforeAcceptInvitation` is that, at the vendor's own seam: the global
`hooks.before` runs before `bearer()` turns a bearer credential into a
session (so it would need a second session read and a user read), and it
would answer ahead of the vendor's recipient check, telling a
non-recipient about someone else's address. The vendor hook gets the
exact user object the vendor's own verification check reads, after the
recipient check, before any write.
### Why not turn the vendor option on where mail is live
`requireEmailVerificationOnInvitation` governs accept, reject and
get-invitation together (`crud-invites.mjs:270/382/505`, better-auth
1.7.12) and is read from options at boot. The narrowing the seat ruled
is accept only, asked per request.
## Tests
`src/invitation-accept-verified-email.test.ts` — real `AuthManager` +
real better-auth pipeline over the memory engine (the
`list-user-invitations-verification.test.ts` shape); the email service's
`isConfigured()` is swapped between requests; every fixture account is
asserted unverified.
1. the local fallback equals the vendor's `$ERROR_CODES` entry;
2. PREMISE: with the option false and no live mail, the vendor lets an
unverified invitee accept;
3. mail live: unverified invitee → 403 with the vendor's code, no
membership, invitation still pending;
4. mail live: a bearer-token session is refused alike;
5. mail live: once the address is verified, the same invitation is
accepted;
6. ORDER PIN: a non-recipient still gets
`YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION`;
7. ONLY ACCEPT: the same unverified invitee still gets, lists and
rejects (200);
8. mail live: the one-step door still accepts with the mail's proof (it
verifies first);
9. no email service: unverified invitee accepts (unchanged);
10. log transport (`isConfigured()` false): unverified invitee accepts
(unchanged);
11. read per request: live → 403, log → 200, live again → 403;
12–14. the function: verified passes without asking; unverified passes
while not live; unverified / unknown user refused while live, with the
entry the caller hands in.
`ui/.../__tests__/acceptInvitationVerifiedEmail-34272.test.tsx` — the
real `createAuthClient` over a stubbed `fetch` answering the server's
403 body: the page navigates to `/verify-email-prompt` with the
account's email and `redirect=/accept-invitation/inv-1`, no toast, no
org switch; CONTROL: `YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION` still
toasts and does not navigate there.
**Ablation.** The hook body made a no-op on disk: tests 3, 4, 5 and 11
red (4 of 14), then restored. The page's routing branch disabled: the UI
routing test red (1 of 2), then restored.
## Verification
Final head `8e828209b5ce1d69a9c3513e319dce15eaa58101`. Measured at
`b2d54a28` (final-head comment 6940567054); `8e828209` changes prose
only (the changeset, the module's header comment and the self-hosting
paragraph, after L1 6940626667), and the 41 derived gates over docs,
changesets and ADR text plus `plugin-auth` typecheck and the module's 14
pins re-ran green on it.
- **Derived gates.** `node scripts/pm/dispatch-gates.mjs --commands`
derived 111 families; all 111 ran, each with its exit code captured, and
all ended exit 0. `--ran` reconciliation: 111 accounted, 111 run, 0
NOT-MEASURED. Four first-run reds were fixed or were prerequisites:
`check:adr-0087-registration` (the changeset's `FROM → TO` label read as
a migration prescription; reworded to prose),
`check:dispatcher-error-vocabulary` (the vendor code needed its
classification row, added), and `spec check:docs` / `spec
check:skill-examples` (stale `packages/spec` build; green after `pnpm
--filter @objectstack/spec build`).
- **Package suites.** `pnpm --filter @objectstack/plugin-auth test` exit
0; `pnpm --filter @objectstack/plugin-auth typecheck` exit 0; `ui`:
`vitest run packages/app-shell/src/console/organizations/` exit 0; `pnpm
--filter @object-ui/app-shell type-check` exit 0 (after building its
workspace dependencies, whose stale `dist` predated #34333).
- **Ablation.** As above: 4 of 14 server pins and 1 of 2 UI pins red
with the change removed, restored after.
- **Dogfood battery** (narrowing): `pnpm --filter @objectstack/dogfood
test` under `scripts/pm/os-verify-lock.sh`, no `OS_TEST_SHARD`, at
`b2d54a28` (the code at `8e828209` is the same; only prose moved): `Test
Files 478 passed | 3 skipped (481)`, `Tests 4055 passed | 68 skipped
(4123)`, `VERDICT command-exit 0`.
- **merge-tree** at the head: clean against `origin/main` `fecd2e95d4`,
which now holds #34617 (the other plugin-auth change in flight at
opening).
## 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.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [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.
- [x] 6. `packages/spec` touched: 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 维护者速读 section is
the maintainer's requested summary.)
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmSYe73LCZ6WxGFvcko
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmSYe73LCZ6WxGFvcko -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent c12fe66 commit c4c0794
11 files changed
Lines changed: 741 additions & 6 deletions
File tree
- .changeset
- content/docs/deployment
- packages
- plugins/plugin-auth/src
- runtime/src
- ui/packages/app-shell/src/console/organizations
- __tests__
- manage
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
760 | 760 | | |
761 | 761 | | |
762 | 762 | | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
763 | 779 | | |
764 | 780 | | |
765 | 781 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
192 | 194 | | |
193 | 195 | | |
194 | 196 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
200 | 206 | | |
201 | 207 | | |
202 | 208 | | |
| |||
425 | 431 | | |
426 | 432 | | |
427 | 433 | | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
428 | 448 | | |
429 | 449 | | |
430 | 450 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
293 | 294 | | |
294 | 295 | | |
295 | 296 | | |
| 297 | + | |
296 | 298 | | |
297 | 299 | | |
298 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2444 | 2444 | | |
2445 | 2445 | | |
2446 | 2446 | | |
| 2447 | + | |
2447 | 2448 | | |
2448 | 2449 | | |
2449 | 2450 | | |
| |||
0 commit comments