Skip to content

Commit 7da458b

Browse files
committed
fix(app-shell)!: an invitation sign-up whose address is not verified goes straight to the verification mail; release notes state one rule
Claude-Session: https://claude.ai/code/session_01QSeKYn5CmmdShCJifm6WYj Co-authored-by: Claude <noreply@anthropic.com>
1 parent 79a6877 commit 7da458b

5 files changed

Lines changed: 74 additions & 28 deletions

File tree

‎.changeset/34272-accept-invitation-verified-email.md‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@
44
'@objectstack/runtime': patch
55
---
66

7-
fix(plugin-auth,app-shell)!: while mail is live, accepting an invitation needs a verified address
7+
fix(plugin-auth,app-shell): an accept refused for an unverified address answers the vendor's own code, and the Console's accept page takes the person to verify
88

9-
Clause-②: no (narrowing)
9+
Clause-②: no
1010
Metadata-protocol: none
11-
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.
11+
Skills-docs: none — `git grep` of `skills/` finds no page that teaches accepting an invitation or `/organization/accept-invitation`; the rule is stated in the self-hosting docs.
1212

13-
<!-- 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. -->
14-
15-
**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.
13+
The rule that refuses the accept is stated, with its BREAKING notice and its migration, in this release's entry "accepting, declining and listing an organization invitation need a verified email address on every deployment, and an invitation sign-up joins by accepting once verified". This entry carries only the parts of that change that ship beside it.
1614

1715
**What changes.**
1816

19-
- `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.
17+
- `POST /api/v1/auth/organization/accept-invitation` (`@objectstack/plugin-auth`) answers a session whose address is unverified with better-auth's own `403 EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION` and its sentence, the answer its accept route gives when its option is on, and writes nothing. 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).
2018
- 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.
2119

22-
**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.
23-
24-
**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.
25-
2620
`@objectstack/runtime` carries only the dispatcher error-vocabulary row that classifies the vendor code above as foreign vocabulary; nothing it runs changes.

‎.changeset/invitation-acceptance-verified-address.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'@objectstack/plugin-auth': patch
33
'@objectstack/verify': patch
44
'@object-ui/app-shell': patch
5-
'@object-ui/console': patch
65
---
76

87
fix(plugin-auth)!: accepting, declining and listing an organization invitation need a verified email address on every deployment, and an invitation sign-up joins by accepting once verified
@@ -18,11 +17,11 @@ Skills-docs: none — no skill under `skills/**` teaches accepting an organizati
1817
- Accepting, declining and listing an organization invitation require a verified email address, on every deployment. A password account verifies by the verification mail; an account a social or SSO provider made counts only when the provider verified the address. The invitation's id, which its accept link and a copied link carry, is no proof of the mailbox, and no setting relaxes the rule.
1918
- Reading one invitation by its id (`GET /api/v1/auth/organization/get-invitation`) stays open, so the accept page can show it.
2019
- Under `invite_only` with `membershipPolicy: 'auto'`, an account a sign-up admitted by the invitation it presents is not bound to the Default Organization while its address is unverified. Its membership comes from accepting the invitation once the address is verified, with the role the invitation carries, or from a platform administrator.
21-
- A deployment without a live mail transport cannot onboard anyone by invitation link.
20+
- A deployment without a live mail transport cannot onboard a password account by invitation link; an invitee whose social or SSO provider verifies the address can still accept a copied link there.
2221

2322
Unchanged: the invitation mail's own link, which carries a proof of the mailbox and accepts in one step (`POST /api/v1/auth/organization/accept-invitation-one-step`); a verified account, which accepts, declines and lists its invitations as before; the first account of a deployment, accounts an administrator creates and accounts a boot command provisions, which are bound as before; sending, resending and cancelling invitations.
2423

25-
The Console's accept-invitation page answers a refused accept or decline with the verification-mail screen for the account's address, whose link brings the person back to answer the invitation.
24+
The Console's accept-invitation page answers a refused decline with the verification-mail screen for the account's address, as it answers a refused accept, and that screen's link brings the person back to answer the invitation.
2625

2726
`@objectstack/verify`: a booted stack's `signUp` mints its fixture member through the operator door (the ticket the stack's own auth manager stages for that address), so the account is bound at creation as before; a stack whose auth service offers no such door falls back to the invitation lane.
2827

‎content/docs/deployment/self-hosting.mdx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,15 @@ in and opens the link from the invitation mail itself needs no separate step:
777777
the accept page offers the one-step form, which verifies the address as it
778778
accepts. No setting relaxes this rule.
779779

780-
**A deployment without a live mail transport cannot onboard anyone by
781-
invitation link.** With no transport configured, or the log transport, no
782-
verification mail and no invitation mail reaches anyone, so no invitee can
783-
verify an address or accept; a link handed over with the invitation's **Copy
784-
Invite Link** action admits the sign-up and nothing more. To bring a person in
785-
there, a platform administrator creates the account
780+
**A deployment without a live mail transport cannot onboard a password
781+
account by invitation link.** With no transport configured, or the log
782+
transport, no verification mail and no invitation mail reaches anyone, so an
783+
invitee who signs up with a password cannot verify the address or accept; a
784+
link handed over with the invitation's **Copy Invite Link** action admits the
785+
sign-up and nothing more. The one exception is an invitee who signs in through
786+
a social or SSO provider that verifies the address: that account counts as
787+
verified, so it can accept a copied link without any mail. To bring anyone
788+
else in there, a platform administrator creates the account
786789
(`POST /api/v1/auth/admin/create-user`), or attaches an account that already
787790
exists with the member list's **Add Member** action. Add Member is open to
788791
platform administrators only, and it attaches existing accounts only: it

‎ui/packages/app-shell/src/console/auth/__tests__/invitationSignUpJoin-30125.test.tsx‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import '@testing-library/jest-dom/vitest';
2929
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
3030
import { render, screen, cleanup, waitFor } from '@testing-library/react';
3131
import userEvent from '@testing-library/user-event';
32-
import { MemoryRouter, Routes, Route } from 'react-router-dom';
32+
import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom';
3333
import { I18nProvider } from '@object-ui/i18n';
3434
import { builtInLocales } from '@object-ui/i18n/locales';
3535
import { AuthProvider } from '@object-ui/auth';
@@ -56,7 +56,7 @@ afterEach(() => {
5656
vi.restoreAllMocks();
5757
});
5858

59-
function createMockClient({ signedInOnArrival = false, refuseRecipient = false } = {}) {
59+
function createMockClient({ signedInOnArrival = false, refuseRecipient = false, refuseUnverified = false } = {}) {
6060
let signedIn = signedInOnArrival;
6161
let member = false;
6262
let active: typeof ORG | null = null;
@@ -84,6 +84,13 @@ function createMockClient({ signedInOnArrival = false, refuseRecipient = false }
8484
return { id, organizationId: ORG.id, email: USER.email, role: 'member', status: 'pending' };
8585
}),
8686
acceptInvitation: vi.fn(async () => {
87+
if (refuseUnverified) {
88+
// The server's answer to an account whose address is not verified.
89+
throw Object.assign(new Error('Email verification required before accepting or rejecting invitation'), {
90+
status: 403,
91+
code: 'EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION',
92+
});
93+
}
8794
member = true;
8895
}),
8996
listOrganizations: vi.fn(async () => (member ? [ORG] : [])),
@@ -107,13 +114,20 @@ function renderRegister(client: AuthClient) {
107114
<Route path="/register" element={<RegisterPage />} />
108115
<Route path="/accept-invitation/:invitationId" element={<p>accept page</p>} />
109116
<Route path="/" element={<p>home</p>} />
117+
<Route path="/verify-email-prompt" element={<VerifyPromptProbe />} />
110118
</Routes>
111119
</MemoryRouter>
112120
</AuthProvider>
113121
</I18nProvider>,
114122
);
115123
}
116124

125+
/** The verification-mail screen's stand-in: shows the query it was opened with. */
126+
function VerifyPromptProbe() {
127+
const location = useLocation();
128+
return <p data-testid="verify-prompt">{location.search}</p>;
129+
}
130+
117131
async function signUpOnTheForm() {
118132
const user = userEvent.setup();
119133
await user.type(await screen.findByLabelText(en.nameLabel), USER.name);
@@ -148,6 +162,20 @@ describe('DefaultRegisterPage — a sign-up from an invitation link joins it (#3
148162
expect(assign).not.toHaveBeenCalled();
149163
});
150164

165+
it('accepting needs a verified address: an unverified account goes straight to the verification mail, which returns to the accept page', async () => {
166+
const client = createMockClient({ refuseUnverified: true });
167+
renderRegister(client);
168+
await signUpOnTheForm();
169+
170+
const prompt = await screen.findByTestId('verify-prompt');
171+
const sp = new URLSearchParams(prompt.textContent ?? '');
172+
expect(sp.get('email')).toBe(USER.email);
173+
expect(sp.get('redirect')).toBe(ACCEPT_PATH);
174+
expect(client.acceptInvitation).toHaveBeenCalledTimes(1);
175+
expect(screen.queryByText('accept page')).toBeNull();
176+
expect(assign).not.toHaveBeenCalled();
177+
});
178+
151179
it('CONTROL: already signed in when the page opens — accepts nothing and goes to /', async () => {
152180
const client = createMockClient({ signedInOnArrival: true });
153181
renderRegister(client);

‎ui/packages/app-shell/src/console/auth/invitationSignUpJoin.ts‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@
2626
* A person who opens the page already signed in accepts nothing here.
2727
* - The server decides as it always does. The page reads the invitation
2828
* (`get-invitation`) and accepts it (`accept-invitation`) as the new
29-
* account; an address that is not the invited one is refused by the server,
30-
* the hook answers `refused`, and the page goes on to the accept page as
31-
* before, which shows that refusal.
29+
* account. An address that is not the invited one is refused by the
30+
* server, the hook answers `refused`, and the page goes on to the accept
31+
* page as before, which shows that refusal.
32+
* - Accepting needs a verified address. An account whose address is not
33+
* verified is refused for that, and the hook hands over straight to the
34+
* verification-mail screen (`/verify-email-prompt`) for the account's
35+
* address, whose link returns to the accept page; it answers `joining`
36+
* meanwhile, so the page holds instead of moving on.
3237
* - A sign-up that waits for email verification creates no session here, so
3338
* nothing is accepted on this page; the verification mail returns to the
3439
* accept page.
40+
* - An account a sign-up admitted by the invitation it presents is not a
41+
* member of any organization until it accepts, so a sign-up whose address
42+
* is not verified lands on the accept page with no organization.
3543
*
3644
* After the acceptance the session is switched to the organization, and the
3745
* page then enters it by a full-page navigation to the console root, the way
@@ -40,8 +48,10 @@
4048
*/
4149

4250
import { useEffect, useRef, useState } from 'react';
51+
import { useNavigate } from 'react-router-dom';
4352
import { useAuth } from '@object-ui/auth';
4453
import { invitationIdOf } from './invitationArrival.js';
54+
import { isAcceptNeedsVerifiedEmail } from '../organizations/orgErrorMessage.js';
4555

4656
/**
4757
* Where a register page's invitation join stands:
@@ -53,7 +63,9 @@ import { invitationIdOf } from './invitationArrival.js';
5363
* - `joined`: the server accepted the invitation and the session is on its
5464
* organization — the page enters the console root;
5565
* - `refused`: the server refused the read or the acceptance — the page goes
56-
* on to the accept page, as it did before.
66+
* on to the accept page, as it did before. A refusal for an unverified
67+
* address is not this outcome: the hook hands over to the verification-mail
68+
* screen and stays `joining`.
5769
*/
5870
export type InvitationSignUpJoin = 'none' | 'joining' | 'joined' | 'refused';
5971

@@ -63,6 +75,7 @@ export type InvitationSignUpJoin = 'none' | 'joining' | 'joined' | 'refused';
6375
*/
6476
export function useInvitationSignUpJoin(redirect: string | null | undefined): InvitationSignUpJoin {
6577
const { user, isLoading, getInvitation, acceptInvitation, switchOrganization } = useAuth();
78+
const navigate = useNavigate();
6679
const invitationId = invitationIdOf(redirect);
6780

6881
// Latched the first time the session check answers with nobody signed in.
@@ -88,7 +101,16 @@ export function useInvitationSignUpJoin(redirect: string | null | undefined): In
88101
const invitation = await getInvitation(id);
89102
await acceptInvitation(id);
90103
organizationId = invitation.organizationId;
91-
} catch {
104+
} catch (err) {
105+
// Accepting needs a verified address: hand over to the verification
106+
// mail, whose link returns to the accept page, and hold meanwhile.
107+
if (isAcceptNeedsVerifiedEmail(err) && redirect) {
108+
const sp = new URLSearchParams();
109+
if (user?.email) sp.set('email', user.email);
110+
sp.set('redirect', redirect);
111+
navigate(`/verify-email-prompt?${sp.toString()}`, { replace: true });
112+
return;
113+
}
92114
setOutcome({ id, result: 'refused' });
93115
return;
94116
}
@@ -97,7 +119,7 @@ export function useInvitationSignUpJoin(redirect: string | null | undefined): In
97119
await switchOrganization(organizationId).catch(() => undefined);
98120
setOutcome({ id, result: 'joined' });
99121
})();
100-
}, [applies, invitationId, getInvitation, acceptInvitation, switchOrganization]);
122+
}, [applies, invitationId, getInvitation, acceptInvitation, switchOrganization, navigate, redirect, user]);
101123

102124
if (!applies) return 'none';
103125
return outcome && outcome.id === invitationId ? outcome.result : 'joining';

0 commit comments

Comments
 (0)