Skip to content

Commit 27b0bc7

Browse files
feat(console): registering from an invitation link joins its organization and enters the app in one step (#30556)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuAQiU42K9ti2tKWY4RZ6E6h)_ Part of #30125 (item 2 here; item 4 landed in PR #30490; items 1 and 3 moved to #30206; item 5 is the devx lane's and stays on the card). Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:被邀请人从邀请链接注册后,注册页直接接受这份邀请、切到该组织并进入应用;不再先停在「接受邀请」页、再停在「邀请已接受 … 继续」页。控制台自己的注册页和 app-shell 的 `DefaultRegisterPage` 行为一致。 - 为什么改:卡片 #30125 第 2 项,通过邀请加入要走三屏;在 main `c045c341` 真栈上实测属实(注册 → 接受邀请 → 邀请已接受·继续 → 应用)。 - 风险与回滚:接受仍由服务端判定,只针对该链接里的那一份邀请,且只在本页刚注册出的会话上发生;打开页面时已登录的人什么都不接受;邮箱不符时服务端照常 403,页面转到原来的接受页显示拒绝。无数据迁移,回滚即还原本 PR。 - 先看:`ui/packages/app-shell/src/console/auth/invitationSignUpJoin.ts`(何时算同意)、`ui/apps/console/src/pages/auth/RegisterPage.tsx` 注册后编排里的 `invitationJoin` 分支、`ui/packages/app-shell/src/console/auth/RegisterPage.tsx` 的 `if (user …)` 三行。 - 两分钟验证:`pnpm --dir ui exec vitest run apps/console/src/pages/auth/__tests__/invitationSignUpJoin-30125.test.tsx packages/app-shell/src/console/auth/__tests__/invitationSignUpJoin-30125.test.tsx`,预期 6 个用例全绿。 - 需要你做的:无,席位落地。 ## What changes Card #30125, **item 2**: joining by invitation took three screens (register, "Accept invitation", "Invitation accepted … Continue"). - **`@object-ui/app-shell`: `useInvitationSignUpJoin(redirect)`** (new export, with type `InvitationSignUpJoin`), in `console/auth/invitationSignUpJoin.ts`. It applies only when the page's `?redirect=` names an invitation (`invitationIdOf`, the same reading as `isInvitationRedirect`) AND the session appeared on the page: the first answered session check found nobody signed in (latched during render, since `isLoading` is raised again by the sign-up in flight). It then reads the invitation (`get-invitation`), accepts it (`accept-invitation`), and switches the session to its organization, once per invitation id. Answers `none`, `joining`, `joined`, or `refused` (any throw before the acceptance lands). - **`@object-ui/console`: `/register`**: the post-sign-up effect holds while `joining`, and on `joined` makes one full-page navigation to the console root (`withConsoleBase('/')`), the way the accept page's Continue does; `refused` falls through to today's steps, which open the accept page, where the server's refusal is shown. - **`@object-ui/app-shell`: `DefaultRegisterPage`**: the same hook. It used to go to `/` after the sign-up and leave the invitation behind; now `joining`/`joined` hold an empty layout, `joined` enters `resolveRootUrl()`, and `refused` navigates to the accept page. A visitor signed in when the page opens still goes to `/` (objectui#11714 unchanged). `onSuccess` no longer navigates for an invitation sign-up, so it cannot race the join. - No new i18n keys: the wait is the pages' existing spinner or empty layout. No server change: `get-invitation`, `accept-invitation` and `set-active` are the routes the accept page already calls. - **Changeset**: `.changeset/30125-invitation-sign-up-joins.md`, `@object-ui/app-shell` patch, `@object-ui/console` patch (`Metadata-protocol: none` grades every entry `patch`). Branch: the harness-assigned `claude/project-thread-lp3y66`, not `claude/issue-30125-*`; the card is #30125. ## Tests Two new files, one per register page, real `AuthProvider` over a mock client whose `getSession` answers the session the sign-up created: - `ui/apps/console/src/pages/auth/__tests__/invitationSignUpJoin-30125.test.tsx` (console mounted under a base href of `/_console/`, as the shipped build is): the sign-up accepts exactly the link's invitation, switches to its organization, and makes exactly one navigation, landing on `/_console/`; the server refusing `get-invitation`: nothing accepted, one navigation to `/_console/accept-invitation/ID`; CONTROL: already signed in on arrival, nothing read or accepted. - `ui/packages/app-shell/src/console/auth/__tests__/invitationSignUpJoin-30125.test.tsx`: the same three for `DefaultRegisterPage` (refusal renders the accept route; signed-in arrival renders `/`). ## Acceptance notes - **Consent boundary.** Accepting stays the invited person's act: only the invitation the page's own link names, only for a session created on that page by registering. An address that is not the invited one gets the server's refusal (403 `get-invitation`, measured live below) and the invitation stays `pending`. Under `invite_only` a sign-up with an address that has no invitation at all is already refused at `sign-up/email` (`SELF_REGISTRATION_CLOSED`), unchanged. - **Email verification on.** A sign-up that waits for verification creates no session on the page, so nothing is accepted there; the verification mail returns to the accept page (objectui#10893), one click as before. Not changed here, on purpose: auto-accepting on that page would let any link with a crafted query accept on behalf of a signed-in person. - **Signing in to an existing account from the invitation link** still goes through the accept page ("Accept invitation", then "Continue"). Item 2 names registration; that path is unchanged. - On a single-organization deployment the new account is already bound to the default organization at sign-up (ADR-0093 D1/D2), and the acceptance adopts that membership (`adopt-membership.ts`); measured live: the invitation turns `accepted`, the account has one organization. - The console's post-sign-up effect on main assigned the accept page twice in the mocked flow (seen in ablation 1 below); with the join, every exit happens once. ## Verification Base `c045c341`. Source head `b81f734a`; the head adds an evidence commit and its removal, the tree is byte-identical to `b81f734a` (`git diff b81f734 HEAD` is empty). <details><summary>Live rig and screenshots (os dev, zh-CN, 1440 wide)</summary> `examples/app-showcase`: `pnpm dev -- --fresh -p PORT` (`objectstack dev --seed-admin`, invite_only, single tenancy), console `vite` from `ui/apps/console` with `DEV_PROXY_TARGET` at that port, Playwright Chromium. The administrator (`admin@objectos.ai`) invites a fresh address over `organization/invite-member`; a clean browser opens `/accept-invitation/ID` signed out, follows "注册并加入", registers that address, and the script records every screen it has to act on until an app route. Before (main `c045c341`, the two register pages restored to the base): sign-up, then `/accept-invitation/ID` with 接受邀请, then 邀请已接受 with 继续, then `/apps/com.example.showcase/...`. Auth requests after the sign-up: `get-invitation` x4, `accept-invitation`, `set-active`. ![before: register](https://github.com/objectstack-ai/objectstack/blob/665dd1b6a9116408f8608e4ccd8973f937dcb08d/evidence/30125-item2/before-2-register-filled-zh-1440.png?raw=true) ![before: accept page](https://github.com/objectstack-ai/objectstack/blob/665dd1b6a9116408f8608e4ccd8973f937dcb08d/evidence/30125-item2/before-4-accept-page-zh-1440.png?raw=true) ![before: invitation accepted, continue](https://github.com/objectstack-ai/objectstack/blob/665dd1b6a9116408f8608e4ccd8973f937dcb08d/evidence/30125-item2/before-5-accepted-continue-zh-1440.png?raw=true) ![before: app](https://github.com/objectstack-ai/objectstack/blob/665dd1b6a9116408f8608e4ccd8973f937dcb08d/evidence/30125-item2/before-6-landed-zh-1440.png?raw=true) After (`b81f734a`): sign-up, then `/apps/com.example.showcase/...` directly, 6.6 s after submit. Requests after the sign-up: `get-invitation` x1, `accept-invitation` x1, `set-active` x1. The invitation reads `accepted` in the administrator's `list-invitations`. ![after: register](https://github.com/objectstack-ai/objectstack/blob/665dd1b6a9116408f8608e4ccd8973f937dcb08d/evidence/30125-item2/after-2-register-filled-zh-1440.png?raw=true) ![after: app, right after the sign-up](https://github.com/objectstack-ai/objectstack/blob/665dd1b6a9116408f8608e4ccd8973f937dcb08d/evidence/30125-item2/after-3-landed-zh-1440.png?raw=true) Mismatch (`b81f734a`): A and B are both invited; B registers from A's link. `sign-up/email` 200 (B has an invitation), `get-invitation` 403, no `accept-invitation` request; the page lands on A's accept page, which shows 邀请不可用 / 您不是该邀请的收件人。 Both invitations still `pending`. ![mismatch: the server refusal on the accept page](https://github.com/objectstack-ai/objectstack/blob/665dd1b6a9116408f8608e4ccd8973f937dcb08d/evidence/30125-item2/after-mismatch-accept-page-refusal-zh-1440.png?raw=true) </details> <details><summary>Tests, ablation, typecheck, lint</summary> - The two new files: Test Files 2 passed (2), Tests 6 passed (6). - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/app-shell/src/console/auth/ packages/app-shell/src/console/organizations/ apps/console/src/pages/auth/` on `b81f734a`: Test Files 59 passed (59), Tests 456 passed (456), lock VERDICT command-exit 0. - Ablation 1 (`scripts/ablation-replace.mjs`, anchor x1 to x0): the hook never applies (`const applies = false && …`): 4 failed / 2 passed (both join cases and both refusal cases; the CONTROLs stay green). Restored, blob equals HEAD, `git diff HEAD` empty. - Ablation 2: the signed-out latch dropped from `applies`: 2 failed / 4 passed (both CONTROL cases: an already signed-in visitor would accept). Restored, blob equals HEAD, `git diff HEAD` empty. - `pnpm --filter @object-ui/app-shell run type-check` and `pnpm --filter @object-ui/console run type-check`: lock VERDICT command-exit 0. - eslint on the six changed source and test files: 0 errors; the 2 warnings are on console `RegisterPage.tsx` lines this PR does not change. </details> <details><summary>Derived gates</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived 35 families on `b81f734a` (the final head's tree is identical). Every one ran and exited 0, each recorded as `command :: exit N`; `--ran` reconciliation: 35 derived, 35 run, 0 NOT-MEASURED (a derived zero). Also `pnpm --dir ui run check:new-line-citations`, `check:control-bytes` and `check:spec-symbols`: exit 0 each. CI runs the rest. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgUk9sDw68FAQ6MtiV8)_ <!-- signed: domain:ui#4 · os-sales · session_01L6bhgVfPeFZkN1FP93imKU --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4bf6e8f commit 27b0bc7

7 files changed

Lines changed: 494 additions & 1 deletion

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
feat(console,app-shell): registering from an invitation link joins that invitation's organization and enters the app in one step
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
- **`@object-ui/console`: `/register`** opened from an invitation link (`?redirect=/accept-invitation/ID`) now accepts THAT invitation as the account the sign-up just created, switches the session to its organization and enters the console root. A new member used to pass three screens: the sign-up, the accept page ("Accept invitation"), and "Invitation accepted … Continue". The server still decides: an address that is not the invited one is refused, nothing is accepted, and the page goes on to the accept page as before, which shows the refusal. A person who opens the page already signed in accepts nothing there, and a sign-up that waits for email verification is accepted from the accept page the verification mail returns to.
12+
- **`@object-ui/app-shell`: `DefaultRegisterPage`** does the same; it used to go to `/` after the sign-up and leave the invitation behind. New export **`useInvitationSignUpJoin(redirect)`**, the one hook both register pages call, answering `none`, `joining`, `joined` or `refused` (type `InvitationSignUpJoin`).

‎ui/apps/console/src/pages/auth/RegisterPage.tsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
* `SELF_REGISTRATION_CLOSED` re-reads the preview, so an invitation that
3434
* went away meanwhile ends the same way and a live one names the address
3535
* it was sent to (#27509).
36+
* - Registered from an invitation link, accepts THAT invitation as the new
37+
* account and enters its organization, instead of stopping on the accept
38+
* page and then on "Invitation accepted" (#30125, app-shell's
39+
* `useInvitationSignUpJoin`). An address the server refuses goes on to the
40+
* accept page as before, which shows the refusal.
3641
*/
3742

3843
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
@@ -51,6 +56,7 @@ import {
5156
InvitationGoneNotice,
5257
invitationArrivalCopy,
5358
useInvitationArrival,
59+
useInvitationSignUpJoin,
5460
} from '@object-ui/app-shell';
5561
import { AuthLayout } from './AuthLayout';
5662
import { followOauthAuthorize } from './followAuthorize';
@@ -116,6 +122,8 @@ export function RegisterPage() {
116122
const ssoHandoffStartedRef = useRef(false);
117123
// And the mobile sign-in hand-off navigation.
118124
const mobileHandoffStartedRef = useRef(false);
125+
// And the entry into the organization an invitation sign-up joined (#30125).
126+
const invitationEntryStartedRef = useRef(false);
119127

120128
// See LoginPage: `isLoading` is overloaded (initial session check + every
121129
// in-flight signUp). Latch once the first check resolves so a failed
@@ -164,6 +172,8 @@ export function RegisterPage() {
164172
const invitationCopy = invitationRedirect
165173
? invitationArrivalCopy('register', invitationArrival.preview, t)
166174
: null;
175+
// #30125 — the sign-up made on this page from an invitation link accepts it.
176+
const invitationJoin = useInvitationSignUpJoin(redirect);
167177

168178
// Sign-up switched off — bounce to /login.
169179
useEffect(() => {
@@ -198,6 +208,18 @@ export function RegisterPage() {
198208
return;
199209
}
200210

211+
// #30125 — registered from an invitation link: hold while the acceptance
212+
// is in flight, then enter the organization it joined. A refusal falls
213+
// through to the steps below, which open the accept page as before.
214+
if (invitationJoin === 'joining') return;
215+
if (invitationJoin === 'joined') {
216+
if (!invitationEntryStartedRef.current) {
217+
invitationEntryStartedRef.current = true;
218+
window.location.assign(withConsoleBase('/'));
219+
}
220+
return;
221+
}
222+
201223
if (!activeOrganization) {
202224
if (isOrganizationsLoading || autoSelectingOrg) return;
203225
if (organizations.length === 1) {
@@ -227,6 +249,7 @@ export function RegisterPage() {
227249
switchOrganization,
228250
handoff.target,
229251
handoff.holdForSignIn,
252+
invitationJoin,
230253
]);
231254

232255
// The first session check has answered and nobody is signed in: the page is
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/**
2+
* #30125 — registering from an invitation link joins that invitation's
3+
* organization and enters the console, instead of stopping on the accept page
4+
* ("Accept invitation") and then on "Invitation accepted … Continue".
5+
*
6+
* Pinned on the console's own `/register`, the page the console routes:
7+
*
8+
* - the sign-up accepts the invitation its `?redirect=` names, switches the
9+
* session to that organization, and leaves for the console root once;
10+
* - the server refusing the read (an address that is not the invited one):
11+
* nothing is accepted and the page opens the accept page, as before;
12+
* - a person already signed in when the page opens accepts nothing here.
13+
*
14+
* The real `AuthProvider` runs over a mock client, so the session appears the
15+
* way a sign-up makes it appear. The Console is mounted as the shipped build
16+
* is (`<base href="/_console/">`), so "the root" is read where the browser
17+
* would land. The package's `DefaultRegisterPage` carries the same pins in
18+
* `packages/app-shell/src/console/auth/__tests__/invitationSignUpJoin-30125.test.tsx`.
19+
*/
20+
21+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22+
import { render, screen, cleanup, waitFor } from '@testing-library/react';
23+
import userEvent from '@testing-library/user-event';
24+
import { MemoryRouter } from 'react-router-dom';
25+
import { AuthProvider } from '@object-ui/auth';
26+
import type { AuthClient } from '@object-ui/auth';
27+
import { RegisterPage } from '../RegisterPage';
28+
29+
const INVITATION_ID = 'inv_30125';
30+
const ACCEPT_PATH = `/accept-invitation/${INVITATION_ID}`;
31+
const ORG = { id: 'org_acme', name: 'Acme', slug: 'acme' };
32+
const USER = { id: 'u_new', name: 'Zhang', email: 'zhang@example.com' };
33+
34+
let baseEl: HTMLBaseElement | null = null;
35+
let assign: ReturnType<typeof vi.fn>;
36+
37+
beforeEach(() => {
38+
window.localStorage.clear();
39+
baseEl = document.createElement('base');
40+
baseEl.setAttribute('href', '/_console/');
41+
document.head.appendChild(baseEl);
42+
vi.stubEnv('BASE_URL', './');
43+
assign = vi.fn();
44+
vi.spyOn(window.location, 'assign').mockImplementation(assign as never);
45+
vi.spyOn(console, 'warn').mockImplementation(() => {});
46+
});
47+
48+
afterEach(() => {
49+
cleanup();
50+
baseEl?.remove();
51+
baseEl = null;
52+
vi.unstubAllEnvs();
53+
vi.restoreAllMocks();
54+
});
55+
56+
interface ServerOptions {
57+
/** Signed in already when the page opens. */
58+
signedInOnArrival?: boolean;
59+
/** `get-invitation` refuses this account (better-auth's recipient check). */
60+
refuseRecipient?: boolean;
61+
}
62+
63+
function createMockClient({ signedInOnArrival = false, refuseRecipient = false }: ServerOptions = {}) {
64+
let signedIn = signedInOnArrival;
65+
let member = false;
66+
let active: typeof ORG | null = null;
67+
const session = () => ({ user: USER, session: { token: 't', createdAt: new Date() } });
68+
const client = {
69+
getSession: vi.fn(async () => (signedIn ? session() : null)),
70+
getConfig: vi.fn().mockResolvedValue({
71+
emailPassword: { enabled: true, disableSignUp: false, requireEmailVerification: false },
72+
features: { audiencePosture: 'invite_only' },
73+
}),
74+
getInvitationPreview: vi.fn().mockResolvedValue({
75+
organizationName: ORG.name,
76+
inviterName: 'Lin',
77+
email: 'z***@example.com',
78+
}),
79+
signUp: vi.fn(async () => {
80+
signedIn = true;
81+
return { user: USER, session: undefined, requiresVerification: false };
82+
}),
83+
getInvitation: vi.fn(async (id: string) => {
84+
if (refuseRecipient) {
85+
throw Object.assign(new Error('You are not the recipient of the invitation'), {
86+
code: 'YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION',
87+
status: 403,
88+
});
89+
}
90+
return { id, organizationId: ORG.id, email: USER.email, role: 'member', status: 'pending' };
91+
}),
92+
acceptInvitation: vi.fn(async () => {
93+
member = true;
94+
}),
95+
listOrganizations: vi.fn(async () => (member ? [ORG] : [])),
96+
getActiveOrganization: vi.fn(async () => active),
97+
getActiveMember: vi.fn().mockResolvedValue(null),
98+
setActiveOrganization: vi.fn(async (id: string) => {
99+
active = id === ORG.id ? ORG : null;
100+
return active;
101+
}),
102+
};
103+
return client as typeof client & AuthClient;
104+
}
105+
106+
function renderRegister(client: AuthClient) {
107+
const search = `?redirect=${encodeURIComponent(ACCEPT_PATH)}`;
108+
window.history.replaceState({}, '', `/_console/register${search}`);
109+
return render(
110+
<AuthProvider authUrl="/api/v1/auth" client={client}>
111+
<MemoryRouter initialEntries={[`/register${search}`]}>
112+
<RegisterPage />
113+
</MemoryRouter>
114+
</AuthProvider>,
115+
);
116+
}
117+
118+
async function signUpOnTheForm() {
119+
const user = userEvent.setup();
120+
await user.type(await screen.findByLabelText('Name'), USER.name);
121+
await user.type(screen.getByLabelText('Email'), USER.email);
122+
await user.type(screen.getByLabelText('Password'), 'hunter2hunter2');
123+
await user.type(screen.getByLabelText('Confirm Password'), 'hunter2hunter2');
124+
await user.click(screen.getByRole('button', { name: 'Create Account' }));
125+
}
126+
127+
/** Where a full-page navigation lands, per the browser's own resolution. */
128+
const lands = (target: string) => new URL(target, document.baseURI).pathname;
129+
130+
describe('console /register — a sign-up from an invitation link joins it (#30125)', () => {
131+
it('accepts the invitation the link names, switches to its organization, and enters the root once', async () => {
132+
const client = createMockClient();
133+
renderRegister(client);
134+
await signUpOnTheForm();
135+
136+
await waitFor(() => expect(assign).toHaveBeenCalled());
137+
expect(client.getInvitation).toHaveBeenCalledWith(INVITATION_ID);
138+
expect(client.acceptInvitation).toHaveBeenCalledTimes(1);
139+
expect(client.acceptInvitation).toHaveBeenCalledWith(INVITATION_ID);
140+
expect(client.setActiveOrganization).toHaveBeenCalledWith(ORG.id);
141+
expect(assign).toHaveBeenCalledTimes(1);
142+
// The root, never the accept page and its "Invitation accepted" step.
143+
expect(lands(assign.mock.calls[0][0] as string)).toBe('/_console/');
144+
});
145+
146+
it('the server refuses this account: accepts nothing and opens the accept page, as before', async () => {
147+
const client = createMockClient({ refuseRecipient: true });
148+
renderRegister(client);
149+
await signUpOnTheForm();
150+
151+
await waitFor(() => expect(assign).toHaveBeenCalled());
152+
expect(client.acceptInvitation).not.toHaveBeenCalled();
153+
expect(assign).toHaveBeenCalledTimes(1);
154+
expect(lands(assign.mock.calls[0][0] as string)).toBe(`/_console${ACCEPT_PATH}`);
155+
});
156+
157+
it('CONTROL: already signed in when the page opens — nothing is accepted, the accept page decides', async () => {
158+
const client = createMockClient({ signedInOnArrival: true });
159+
renderRegister(client);
160+
161+
await waitFor(() => expect(assign).toHaveBeenCalled());
162+
expect(client.getInvitation).not.toHaveBeenCalled();
163+
expect(client.acceptInvitation).not.toHaveBeenCalled();
164+
expect(lands(assign.mock.calls[0][0] as string)).toBe(`/_console${ACCEPT_PATH}`);
165+
});
166+
});

‎ui/packages/app-shell/src/console/auth/RegisterPage.tsx‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
* with `SELF_REGISTRATION_CLOSED` re-reads the preview, so an invitation that
3131
* went away meanwhile ends the same way, and a live one names the address it
3232
* was sent to (#27509, `./invitationArrival`).
33+
*
34+
* Registered from an invitation link, the new account accepts THAT invitation
35+
* and enters its organization at the console root, instead of going on to the
36+
* accept page and its "Invitation accepted" step (#30125,
37+
* `./invitationSignUpJoin`); an address the server refuses goes on to the
38+
* accept page, which shows the refusal. A visitor already signed in when the
39+
* page opened still goes to `/` and accepts nothing here.
3340
*/
3441

3542
import { useEffect, useState } from 'react';
@@ -49,6 +56,8 @@ import { decideSignUpOffer, isInvitationRedirect, needsBootstrapProbe } from './
4956
import { useBootstrapStatus } from './bootstrapStatus.js';
5057
import { ServerUnreachable } from './LoginPage.js';
5158
import { InvitationGoneNotice, invitationArrivalCopy, useInvitationArrival } from './invitationArrival.js';
59+
import { useInvitationSignUpJoin } from './invitationSignUpJoin.js';
60+
import { resolveRootUrl } from '../organizations/resolveHomeUrl.js';
5261

5362
const RouterLink = ({ href, className, children }: AuthLinkComponentProps) => (
5463
<Link to={href} className={className}>{children}</Link>
@@ -115,6 +124,13 @@ export function RegisterPage() {
115124
// #26473 — who invited this visitor, and to what; `null` keeps the generic
116125
// copy. #27509 — `gone` when the server no longer knows the invitation.
117126
const invitationArrival = useInvitationArrival(redirect);
127+
// #30125 — the sign-up made on this page from an invitation link accepts it.
128+
const invitationJoin = useInvitationSignUpJoin(redirect);
129+
// Entered by a full-page navigation to the root, as the accept page's
130+
// "Continue" does: every data scope re-seats on the joined organization.
131+
useEffect(() => {
132+
if (invitationJoin === 'joined') window.location.assign(resolveRootUrl());
133+
}, [invitationJoin]);
118134

119135
// Sign-up switched off — bounce a signed-out visitor to /login, keeping
120136
// `?redirect=`. A signed-in one is moved on below instead, never to /login.
@@ -124,6 +140,13 @@ export function RegisterPage() {
124140
navigate(`/login${search}`, { replace: true });
125141
}, [signedOut, signUpOffer, navigate, redirect]);
126142

143+
// #30125 — the invitation sign-up holds while it is accepted and while the
144+
// page leaves for the root; refused, it opens the accept page as before.
145+
if (user && (invitationJoin === 'joining' || invitationJoin === 'joined')) {
146+
return <AuthPageLayout>{null}</AuthPageLayout>;
147+
}
148+
if (user && invitationJoin === 'refused' && redirect) return <Navigate to={redirect} replace />;
149+
127150
// objectui#11714 — signed in: go where a successful sign-up goes, without
128151
// waiting for the config or the probe. `<Navigate>` renders nothing.
129152
if (user) return <Navigate to="/" replace />;
@@ -243,7 +266,10 @@ export function RegisterPage() {
243266
return (
244267
<AuthPageLayout>
245268
<RegisterForm
246-
onSuccess={() => navigate('/')}
269+
// An invitation sign-up moves on from the join above (#30125).
270+
onSuccess={() => {
271+
if (!invitationRedirect) navigate('/');
272+
}}
247273
onVerificationRequired={(email) => setPendingEmail(email)}
248274
loginUrl={loginUrl}
249275
// #25886 — an invitee is told to register the invited address: the

0 commit comments

Comments
 (0)