Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/34272-accept-invitation-verified-email.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@objectstack/plugin-auth': patch
'@object-ui/app-shell': patch
'@objectstack/runtime': patch
---

fix(plugin-auth,app-shell)!: while mail is live, accepting an invitation needs a verified address

Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — `git grep` of `skills/` finds no page that teaches accepting an invitation or `/organization/accept-invitation`; the rule is stated here and in the self-hosting docs.

<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value, metadata type or stored row is added, removed, renamed or rewritten: the moved answer is whether one auth route accepts a request from a session whose address is unverified, while the deployment's mail transport is live. Nothing exists for a migration to rewrite; the one-line fix for a refused person is in the body: verify the address, then accept. -->

**BREAKING** for a person who accepts an invitation from an account whose address was never verified, on a deployment whose mail transport is live. The rule: while mail is live, accepting an invitation needs a verified address, because an unverified address is not proof of the invited mailbox.

**What changes.**

- `POST /api/v1/auth/organization/accept-invitation` (`@objectstack/plugin-auth`), from a session whose address is unverified, while the email service answers `isConfigured() === true`, now answers `403 EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION` (better-auth's own code and sentence, the ones its accept route answers when its option is on) and writes nothing; the invitation stays pending. It used to answer `200` and write the membership. The vendor's not-found, expiry and recipient refusals still come first, so a session that is not the invitee learns nothing new. The check runs on the vendor's `beforeAcceptInvitation` hook, on the session user the vendor itself resolved (cookie or bearer token alike), and asks whether mail is live on every request.
- The Console's accept page (`@object-ui/app-shell`) answers that refusal with the verification-mail screen (`/verify-email-prompt`) for the account's address, whose link returns to the accept page, instead of a toast.

**Who moves.** A person in that state verifies their address (the Console's accept page takes them to the screen that sends the mail), then accepts; an API client that accepts for its user does the same, through `POST /api/v1/auth/send-verification-email`. A visitor who is not signed in and opens the invitation mail's own link is not affected: the accept page offers the one-step form, which verifies the address as it accepts. A visitor already signed in to an account whose address is unverified who opens the same link accepts through `/organization/accept-invitation`, so is refused as above and sent to verify.

**Unchanged.** Every deployment without a live mail transport (no email service, or the log transport), where nothing could verify an address, so acceptance stays open to an unverified address; `get-invitation`, `list-user-invitations` and `reject-invitation`, which write no membership; the one-step door `POST /api/v1/auth/organization/accept-invitation-one-step`; and a verified session everywhere. better-auth's `requireEmailVerificationOnInvitation` stays declared `false`: it governs reading and declining too, and is read once at boot.

`@objectstack/runtime` carries only the dispatcher error-vocabulary row that classifies the vendor code above as foreign vocabulary; nothing it runs changes.
16 changes: 16 additions & 0 deletions content/docs/deployment/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,22 @@ reaches the invitee in the invitation mail; on a deployment with no mail
transport, an administrator hands it over with the invitation's **Copy Invite
Link** action. The first account of a new deployment needs no invitation.

**While the mail transport is live, accepting an invitation needs a verified
address.** `POST /api/v1/auth/organization/accept-invitation` from a session
whose address was never verified answers `403
EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION` and
writes nothing: an unverified address does not prove the person holds the
invited mailbox. The Console's accept page sends the person to the
verification-mail screen for their address, and the link in that mail brings
them back to accept. A visitor who is not signed in and opens the invitation's
link from the invitation mail itself needs no separate step: the accept page
offers the one-step form, which verifies the address as it accepts. A visitor
already signed in to an unverified account who opens that link is sent to
verify first, like any other unverified session. Reading, listing and declining an invitation are not affected. On a
deployment with no live transport (none configured, or the log transport)
nothing can verify an address, so acceptance stays open to an unverified
address, as before.

**What decides it on `open` and `email_domain`.** A sign-up for an address that
already has an account gets the same answer as a successful new sign-up, and
writes nothing, when all three of these hold:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
import { buildOrganizationPluginSchema } from './auth-schema-config.js';
import { CLOUD_MANAGED_REFUSAL_CODE, CLOUD_MANAGED_REFUSAL_MESSAGES } from './cloud-managed.js';
import { resolveInvitationLimitOption } from './invitation-limit.js';
import { refuseUnverifiedAcceptWhileMailIsLive } from './invitation-accept-verified-email.js';
import { invitationAcceptPath } from './invitation-link-action.js';
import { invitationRoleCapFailure, isPlainMemberInvitation } from './invitation-role-cap.js';
import { blankInvitationRoleRefusal } from './invite-role-not-found-code.js';
Expand Down Expand Up @@ -108,6 +109,7 @@ export interface OrganizationPluginHost {
getConsolePageUrl: AuthManager['getConsolePageUrl'];
getDataEngine: AuthManager['getDataEngine'];
getEmailService: AuthManager['getEmailService'];
isEmailDeliveryLive: AuthManager['isEmailDeliveryLive'];
multiOrgPostureEffective: AuthManager['multiOrgPostureEffective'];
orgRolesMap: AuthManager['orgRolesMap'];
resolveMembershipRole: AuthManager['resolveMembershipRole'];
Expand Down Expand Up @@ -192,11 +194,15 @@ export async function buildOrganizationPlugin(this: OrganizationPluginHost) {
// portal exposes a Teams page; without this flag those endpoints
// 404 and the section silently breaks.
teams: { enabled: true },
// Without a mailer wired in framework, requiring email verification
// before accepting invitations dead-ends every invite flow with
// FORBIDDEN EMAIL_VERIFICATION_REQUIRED…. Default-off here keeps
// the built-in /accept-invitation route usable for pilots; operators
// who wire a real mailer can re-enable downstream.
// The vendor's switch governs accept, reject and get-invitation
// together, and is read once, at boot. Declared off here: on a
// deployment with no live mail nothing can ever verify an address, so
// turning it on would dead-end every invite flow with FORBIDDEN
// EMAIL_VERIFICATION_REQUIRED…. [#34272] Where mail IS live, the
// accept door alone still refuses an unverified session, asked per
// request by `beforeAcceptInvitation` below
// (`invitation-accept-verified-email.ts`); reading and declining an
// invitation stay open, as does every door while mail is not live.
requireEmailVerificationOnInvitation: false,
// Cap how many orgs a user can CREATE (OS_ORG_LIMIT). Counts only orgs
// the user OWNS (role=owner) — never orgs they were merely invited into —
Expand Down Expand Up @@ -425,6 +431,20 @@ export async function buildOrganizationPlugin(this: OrganizationPluginHost) {
});
}
},
// [#34272] While mail is live, an unverified session may not accept:
// the address it holds was never proven to be the invitee's mailbox.
// Fired by the vendor inside the accept endpoint, after its recipient
// and expiry checks and before anything is written, with the
// `session.user` its own verification check reads. A no-op while mail
// is not live. `invitation-accept-verified-email.ts` states the rule.
beforeAcceptInvitation: async ({ user }: any) => {
await refuseUnverifiedAcceptWhileMailIsLive(user, {
isEmailDeliveryLive: () => this.isEmailDeliveryLive(),
verificationRequired:
organizationPlugin?.$ERROR_CODES
?.EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION,
});
},
// [ADR-0105 D8] Accept-time application + host seam. The placement
// the issuance gate approved lands WITH the better-auth membership,
// so the invitee arrives already in the right unit and role. The
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/plugin-auth/src/auth-manager-plugin-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export interface PluginListHost {
getEmailService: AuthManager['getEmailService'];
getMcpResourceUrl: AuthManager['getMcpResourceUrl'];
getApi: AuthManager['getApi'];
isEmailDeliveryLive: AuthManager['isEmailDeliveryLive'];
isPlatformAdminUserId: AuthManager['isPlatformAdminUserId'];
isSsoOnlyMode: AuthManager['isSsoOnlyMode'];
jwtSigningFailureReported: AuthManager['jwtSigningFailureReported'];
Expand Down Expand Up @@ -293,6 +294,7 @@ export async function buildPluginList(this: PluginListHost): Promise<any[]> {
getConsolePageUrl: (...a) => this.getConsolePageUrl(...a),
getDataEngine: (...a) => this.getDataEngine(...a),
getEmailService: (...a) => this.getEmailService(...a),
isEmailDeliveryLive: (...a) => this.isEmailDeliveryLive(...a),
multiOrgPostureEffective: (...a) => this.multiOrgPostureEffective(...a),
get orgRolesMap() { return readOrgRolesMap(); },
set orgRolesMap(v) { writeOrgRolesMap(v); },
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/plugin-auth/src/auth-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2444,6 +2444,7 @@ export class AuthManager {
getEmailService: (...a) => this.getEmailService(...a),
getMcpResourceUrl: (...a) => this.getMcpResourceUrl(...a),
getApi: (...a) => this.getApi(...a),
isEmailDeliveryLive: (...a) => this.isEmailDeliveryLive(...a),
isPlatformAdminUserId: (...a) => this.isPlatformAdminUserId(...a),
isSsoOnlyMode: (...a) => this.isSsoOnlyMode(...a),
get jwtSigningFailureReported() { return readJwtSigningFailureReported(); },
Expand Down
Loading
Loading