Skip to content

Commit b00d5fb

Browse files
committed
feat(ui): read the signed-out invitation preview on the invitation login and register pages (wip)
Claude-Session: https://claude.ai/code/session_01SMps7wq7rBTk53e8KTSEup Co-authored-by: Claude <noreply@anthropic.com>
1 parent 00a4593 commit b00d5fb

12 files changed

Lines changed: 278 additions & 44 deletions

File tree

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
* (`?redirect=/accept-invitation/ID`) is greeted for that invitation instead
3131
* of as a returning user, and, where sign-up is offered, gets app-shell's
3232
* `InvitationSignUpPrompt` above the form in place of the small "Sign up"
33-
* link — the same prompt `DefaultLoginPage` shows (#25886).
33+
* link — the same prompt `DefaultLoginPage` shows (#25886). The greeting
34+
* names the organization and the inviter when the signed-out invitation
35+
* preview answers, with the masked invited address as the one to use (#26473,
36+
* app-shell's `useInvitationPreview`); otherwise it keeps the generic copy.
3437
*
3538
* Layout (objectui#12600): one 400 px column — brand mark, the card, a footer.
3639
* The card carries this page's own two-line header, so `<LoginForm>` renders
@@ -60,6 +63,8 @@ import {
6063
needsBootstrapProbe,
6164
useBootstrapStatus,
6265
InvitationSignUpPrompt,
66+
invitationArrivalCopy,
67+
useInvitationPreview,
6368
} from '@object-ui/app-shell';
6469
import { AuthLayout } from './AuthLayout';
6570
import { AuthFooter, readLegalLinks } from './AuthFooter';
@@ -153,6 +158,11 @@ export function LoginPage() {
153158
hasBootstrapped && !user && needsBootstrapProbe(authConfig, invitationRedirect),
154159
);
155160
const signUpOffer = decideSignUpOffer(authConfig, { invitationRedirect, bootstrap });
161+
// #26473 — who invited this visitor, and to what; `null` keeps the generic copy.
162+
const invitationPreview = useInvitationPreview(redirect);
163+
const invitationCopy = invitationRedirect
164+
? invitationArrivalCopy('login', invitationPreview, t)
165+
: null;
156166

157167
// Detect SSO hand-off so we can surface the relying-party host.
158168
const ssoTarget = useMemo(() => {
@@ -327,15 +337,13 @@ export function LoginPage() {
327337
<>
328338
<div className="mb-5">
329339
<h1 className="text-xl font-semibold tracking-tight text-foreground">
330-
{invitationRedirect
331-
? t('auth.login.invitationTitle', { defaultValue: 'Accept your invitation' })
340+
{invitationCopy
341+
? invitationCopy.title
332342
: t('auth.login.welcomeTitle', { defaultValue: 'Welcome back' })}
333343
</h1>
334344
<p className="mt-1 text-[13px] text-muted-foreground">
335-
{invitationRedirect
336-
? t('auth.login.invitationDescription', {
337-
defaultValue: 'Use the email address the invitation was sent to.',
338-
})
345+
{invitationCopy
346+
? invitationCopy.description
339347
: t('auth.login.welcomeDescription', {
340348
defaultValue: 'Sign in to continue your work',
341349
})}

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
isInvitationRedirect,
4141
needsBootstrapProbe,
4242
useBootstrapStatus,
43+
invitationArrivalCopy,
44+
useInvitationPreview,
4345
} from '@object-ui/app-shell';
4446
import { AuthLayout } from './AuthLayout';
4547
import { followOauthAuthorize } from './followAuthorize';
@@ -138,6 +140,11 @@ export function RegisterPage() {
138140
needsBootstrapProbe(authConfig, invitationRedirect),
139141
);
140142
const signUpOffer = decideSignUpOffer(authConfig, { invitationRedirect, bootstrap });
143+
// #26473 — who invited this visitor, and to what; `null` keeps the generic copy.
144+
const invitationPreview = useInvitationPreview(redirect);
145+
const invitationCopy = invitationRedirect
146+
? invitationArrivalCopy('register', invitationPreview, t)
147+
: null;
141148

142149
// Sign-up switched off — bounce to /login.
143150
useEffect(() => {
@@ -263,18 +270,17 @@ export function RegisterPage() {
263270
<Card className="border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95">
264271
<RegisterForm
265272
// #25886 — an invitee is told to register the invited address: the
266-
// invitation is accepted only by the account that carries it.
273+
// invitation is accepted only by the account that carries it. #26473 —
274+
// with the preview, the card names the inviter and the organization,
275+
// and shows the masked address; the email field stays empty.
267276
title={
268-
invitationRedirect
269-
? t('auth.register.invitationTitle', { defaultValue: 'Create an account to join' })
277+
invitationCopy
278+
? invitationCopy.title
270279
: t('auth.register.title', { defaultValue: 'Create an account' })
271280
}
272281
description={
273-
invitationRedirect
274-
? t('auth.register.invitationDescription', {
275-
defaultValue:
276-
'Register with the email address the invitation was sent to. The invitation can only be accepted with that address.',
277-
})
282+
invitationCopy
283+
? invitationCopy.description
278284
: t('auth.register.description', {
279285
defaultValue: 'Create your account to start building.',
280286
})

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
* is greeted for that invitation instead of as a returning user, and, where
2020
* sign-up is offered, gets `InvitationSignUpPrompt` (`./invitationArrival`)
2121
* above the form in place of the small "Sign up" link (#25886). The console's
22-
* own login page does the same.
22+
* own login page does the same. The greeting names the organization and the
23+
* inviter when the signed-out invitation preview answers (#26473,
24+
* `useInvitationPreview`), and keeps the generic copy when it does not.
2325
*/
2426

2527
import { useEffect, useState } from 'react';
@@ -39,7 +41,11 @@ import { AuthPageLayout } from './AuthPageLayout.js';
3941
import { signInRefusalMessages } from './signInRefusalMessages.js';
4042
import { decideSignUpOffer, isInvitationRedirect, needsBootstrapProbe } from './signUpOffer.js';
4143
import { useBootstrapStatus } from './bootstrapStatus.js';
42-
import { InvitationSignUpPrompt } from './invitationArrival.js';
44+
import {
45+
InvitationSignUpPrompt,
46+
invitationArrivalCopy,
47+
useInvitationPreview,
48+
} from './invitationArrival.js';
4349

4450
const RouterLink = ({ href, className, children }: AuthLinkComponentProps) => (
4551
<Link to={href} className={className}>{children}</Link>
@@ -120,6 +126,8 @@ export function LoginPage() {
120126
// did not come from an invitation; see `./signUpOffer`.
121127
const invitationRedirect = isInvitationRedirect(redirect);
122128
const bootstrap = useBootstrapStatus(!user && needsBootstrapProbe(authConfig, invitationRedirect));
129+
// #26473 — who invited this visitor, and to what; `null` keeps the generic copy.
130+
const invitationPreview = useInvitationPreview(redirect);
123131
const signUpOffer = decideSignUpOffer(authConfig, { invitationRedirect, bootstrap });
124132

125133
// Carry `?redirect=` into the sign-up link: it is how `/register` knows the
@@ -195,16 +203,15 @@ export function LoginPage() {
195203

196204
if (!invitationRedirect) return <AuthPageLayout>{form}</AuthPageLayout>;
197205

206+
const invitationCopy = invitationArrivalCopy('login', invitationPreview, t);
207+
198208
return (
199209
<AuthPageLayout>
200210
<div
201211
data-testid="login-invitation-arrival"
202212
className="mx-auto flex w-full flex-col justify-center space-y-6 sm:max-w-[400px]"
203213
>
204-
<AuthFormHeader
205-
title={t('auth.login.invitationTitle')}
206-
description={t('auth.login.invitationDescription')}
207-
/>
214+
<AuthFormHeader title={invitationCopy.title} description={invitationCopy.description} />
208215
{invitationSignUpUrl ? <InvitationSignUpPrompt registerUrl={invitationSignUpUrl} /> : null}
209216
{form}
210217
</div>

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { signUpRefusalMessages } from './signUpRefusalMessages.js';
4242
import { decideSignUpOffer, isInvitationRedirect, needsBootstrapProbe } from './signUpOffer.js';
4343
import { useBootstrapStatus } from './bootstrapStatus.js';
4444
import { ServerUnreachable } from './LoginPage.js';
45+
import { invitationArrivalCopy, useInvitationPreview } from './invitationArrival.js';
4546

4647
const RouterLink = ({ href, className, children }: AuthLinkComponentProps) => (
4748
<Link to={href} className={className}>{children}</Link>
@@ -105,6 +106,8 @@ export function RegisterPage() {
105106
const signedOut = sessionChecked && !user;
106107
const bootstrap = useBootstrapStatus(signedOut && needsBootstrapProbe(authConfig, invitationRedirect));
107108
const signUpOffer = decideSignUpOffer(authConfig, { invitationRedirect, bootstrap });
109+
// #26473 — who invited this visitor, and to what; `null` keeps the generic copy.
110+
const invitationPreview = useInvitationPreview(redirect);
108111

109112
// Sign-up switched off — bounce a signed-out visitor to /login, keeping
110113
// `?redirect=`. A signed-in one is moved on below instead, never to /login.
@@ -132,6 +135,7 @@ export function RegisterPage() {
132135
}
133136

134137
const loginUrl = redirect ? `/login?redirect=${encodeURIComponent(redirect)}` : '/login';
138+
const invitationCopy = invitationRedirect ? invitationArrivalCopy('register', invitationPreview, t) : null;
135139

136140
// Registration here is by invitation only. Say so BEFORE the form; the
137141
// sentence is the `SELF_REGISTRATION_CLOSED` refusal's own copy, the same
@@ -226,13 +230,11 @@ export function RegisterPage() {
226230
onVerificationRequired={(email) => setPendingEmail(email)}
227231
loginUrl={loginUrl}
228232
// #25886 — an invitee is told to register the invited address: the
229-
// invitation is accepted only by the account that carries it.
230-
title={invitationRedirect ? t('auth.register.invitationTitle') : t('auth.register.title')}
231-
description={
232-
invitationRedirect
233-
? t('auth.register.invitationDescription')
234-
: t('auth.register.description')
235-
}
233+
// invitation is accepted only by the account that carries it. #26473 —
234+
// with the preview, the card names the inviter and the organization,
235+
// and shows the masked address; the email field stays empty.
236+
title={invitationCopy ? invitationCopy.title : t('auth.register.title')}
237+
description={invitationCopy ? invitationCopy.description : t('auth.register.description')}
236238
linkComponent={RouterLink}
237239
errorMessages={signUpRefusalMessages(t)}
238240
labels={{

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

Lines changed: 126 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,37 @@
77
*/
88

99
/**
10-
* invitationArrival — the register-first action a login page shows a visitor
11-
* who arrived signed out from an invitation link (#25886).
10+
* invitationArrival — what a login or register page shows a visitor who
11+
* arrived signed out from an invitation link (#25886, #26473).
1212
*
1313
* `DefaultAcceptInvitationPage` bounces a signed-out visitor to
1414
* `/login?redirect=/accept-invitation/ID` (`isInvitationRedirect` in
1515
* `./signUpOffer`). Most invitees have never had an account here, so for them
1616
* the generic "Welcome back" card with a small "Sign up" link under the form
1717
* read as the wrong site. Both login pages — the console's own
1818
* (`apps/console/src/pages/auth/LoginPage.tsx`) and this package's
19-
* `DefaultLoginPage` — retitle the card for that visitor and render this
20-
* prompt above the form in place of the small link, so there is ONE prompt and
21-
* no second copy of it.
19+
* `DefaultLoginPage` — retitle the card for that visitor and render
20+
* `InvitationSignUpPrompt` above the form in place of the small link, so there
21+
* is ONE prompt and no second copy of it. Both register pages retitle theirs.
2222
*
23-
* The prompt names no organization and no inviter: the only invitation read
24-
* the server serves (`GET /organization/get-invitation`) answers a signed-out
25-
* caller `401`, and an anonymous preview is a server decision this package
26-
* does not make. It is rendered only when the page's sign-up offer is `form`,
23+
* The title names the organization and the inviter when the server's
24+
* signed-out preview answers for the id the link carries
25+
* (`useInvitationPreview`, `GET {authUrl}/organization/invitation-preview`):
26+
* "Lin invited you to join Acme". The invited address comes back MASKED
27+
* (`z***@example.com`), so the description shows it as the address to use and
28+
* nothing prefills it: a masked value is not an address. An id the server does
29+
* not know (404), a failed read, or a server without the route keeps the
30+
* generic copy (`invitationArrivalCopy`) — the preview only ever adds names.
31+
*
32+
* The sign-up prompt is rendered only when the page's sign-up offer is `form`,
2733
* so a server with sign-up switched off is never offered a registration it
2834
* refuses.
2935
*/
3036

37+
import { useEffect, useState } from 'react';
3138
import { Link } from 'react-router-dom';
32-
import { useObjectTranslation } from '@object-ui/i18n';
39+
import { useAuth, type AuthInvitationPreview } from '@object-ui/auth';
40+
import { useObjectTranslation, type TranslateFn } from '@object-ui/i18n';
3341

3442
/** A full-width outlined link with the auth primary button's box. */
3543
const INVITATION_SIGN_UP_CLASS =
@@ -59,3 +67,111 @@ export function InvitationSignUpPrompt({ registerUrl }: { registerUrl: string })
5967
</div>
6068
);
6169
}
70+
71+
/** The basename-stripped route an invitation link opens, as `./signUpOffer` reads it. */
72+
const INVITATION_ROUTE_PREFIX = '/accept-invitation/';
73+
74+
/**
75+
* The invitation id a `?redirect=` target carries, or `null` when it is not an
76+
* invitation-acceptance path. Reads the same segment `isInvitationRedirect`
77+
* tests for, so the two agree on which redirects are invitations.
78+
*/
79+
export function invitationIdOf(redirect: string | null | undefined): string | null {
80+
if (!redirect || !redirect.startsWith(INVITATION_ROUTE_PREFIX)) return null;
81+
const segment = redirect.slice(INVITATION_ROUTE_PREFIX.length).split(/[/?#]/, 1)[0];
82+
if (!segment) return null;
83+
try {
84+
return decodeURIComponent(segment);
85+
} catch {
86+
// A malformed escape is still the segment the link carried; the server
87+
// answers its uniform 404 for it.
88+
return segment;
89+
}
90+
}
91+
92+
/**
93+
* The signed-out invitation preview for the page's `?redirect=`, or `null`.
94+
*
95+
* `null` until the read answers, for a redirect that is not an invitation, for
96+
* the server's not-found answer, and after a failed read: each of those keeps
97+
* the page's generic invitation copy, and none of them throws into the page.
98+
* Only an answer for the CURRENT id is returned, so a page whose redirect
99+
* changes never shows the previous invitation's names.
100+
*/
101+
export function useInvitationPreview(redirect: string | null | undefined): AuthInvitationPreview | null {
102+
const { getInvitationPreview } = useAuth();
103+
const invitationId = invitationIdOf(redirect);
104+
const [answer, setAnswer] = useState<{ id: string; preview: AuthInvitationPreview } | null>(null);
105+
useEffect(() => {
106+
if (!invitationId) return;
107+
let cancelled = false;
108+
// Inside the chain, so a synchronous throw is a rejection like any other.
109+
Promise.resolve()
110+
.then(() => getInvitationPreview(invitationId))
111+
.then(
112+
(preview) => {
113+
if (!cancelled && preview) setAnswer({ id: invitationId, preview });
114+
},
115+
() => {
116+
// A failed read is not news for this page: the generic copy stays,
117+
// and the sign-in or sign-up request reports the server for itself.
118+
},
119+
);
120+
return () => {
121+
cancelled = true;
122+
};
123+
}, [invitationId, getInvitationPreview]);
124+
return answer && answer.id === invitationId ? answer.preview : null;
125+
}
126+
127+
/**
128+
* The invitation card's title and description for one of the two pages: with
129+
* a preview, "INVITER invited you to join ORG" (or "You are invited to join
130+
* ORG" when the inviter has no name) over the masked address to use; without
131+
* one, the generic copy each page showed before the preview existed.
132+
*/
133+
export function invitationArrivalCopy(
134+
page: 'login' | 'register',
135+
preview: AuthInvitationPreview | null,
136+
t: TranslateFn,
137+
): { title: string; description: string } {
138+
if (!preview) {
139+
return page === 'login'
140+
? {
141+
title: t('auth.login.invitationTitle', { defaultValue: 'Accept your invitation' }),
142+
description: t('auth.login.invitationDescription', {
143+
defaultValue: 'Use the email address the invitation was sent to.',
144+
}),
145+
}
146+
: {
147+
title: t('auth.register.invitationTitle', { defaultValue: 'Create an account to join' }),
148+
description: t('auth.register.invitationDescription', {
149+
defaultValue:
150+
'Register with the email address the invitation was sent to. The invitation can only be accepted with that address.',
151+
}),
152+
};
153+
}
154+
const organization = preview.organizationName;
155+
const title = preview.inviterName
156+
? t('auth.login.invitationPreviewTitle', {
157+
defaultValue: '{{inviter}} invited you to join {{organization}}',
158+
inviter: preview.inviterName,
159+
organization,
160+
})
161+
: t('auth.login.invitationPreviewTitleNoInviter', {
162+
defaultValue: 'You are invited to join {{organization}}',
163+
organization,
164+
});
165+
const description =
166+
page === 'login'
167+
? t('auth.login.invitationPreviewDescription', {
168+
defaultValue: 'Use the email address the invitation was sent to ({{email}}).',
169+
email: preview.email,
170+
})
171+
: t('auth.register.invitationPreviewDescription', {
172+
defaultValue:
173+
'Register with the email address the invitation was sent to ({{email}}). The invitation can only be accepted with that address.',
174+
email: preview.email,
175+
});
176+
return { title, description };
177+
}

‎ui/packages/app-shell/src/index.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,13 @@ export {
273273
} from './console/auth/signUpOffer.js';
274274
export { useBootstrapStatus, type BootstrapStatus } from './console/auth/bootstrapStatus.js';
275275
// The register-first prompt both login pages show a signed-out visitor who
276-
// arrived from an invitation link (#25886).
277-
export { InvitationSignUpPrompt } from './console/auth/invitationArrival.js';
276+
// arrived from an invitation link (#25886), and the signed-out invitation
277+
// preview both login and both register pages greet that visitor with (#26473).
278+
export {
279+
InvitationSignUpPrompt,
280+
invitationArrivalCopy,
281+
useInvitationPreview,
282+
} from './console/auth/invitationArrival.js';
278283
export { ForgotPasswordPage as DefaultForgotPasswordPage } from './console/auth/ForgotPasswordPage.js';
279284
export { HomeLayout as DefaultHomeLayout, HomeLayout } from './console/home/HomeLayout.js';
280285
export { HomePage as DefaultHomePage, HomePage } from './console/home/HomePage.js';

‎ui/packages/auth/src/AuthContext.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { createContext } from 'react';
10-
import type { AuthUser, AuthClientSession, PreviewModeOptions, AuthOrganization, AuthOrganizationMember, AuthInvitation, AuthPublicConfig, SignInWithProviderOptions, DelegableScope } from './types.js';
10+
import type { AuthUser, AuthClientSession, PreviewModeOptions, AuthOrganization, AuthOrganizationMember, AuthInvitation, AuthInvitationPreview, AuthPublicConfig, SignInWithProviderOptions, DelegableScope } from './types.js';
1111

1212
export interface AuthContextValue {
1313
/** Current authenticated user */
@@ -190,6 +190,11 @@ export interface AuthContextValue {
190190
cancelInvitation: (invitationId: string) => Promise<void>;
191191
/** Get invitation details by id */
192192
getInvitation: (invitationId: string) => Promise<AuthInvitation>;
193+
/**
194+
* The signed-out invitation preview: `null` when the server does not know
195+
* the id (or it is no longer pending); rejects on any other failure.
196+
*/
197+
getInvitationPreview: (invitationId: string) => Promise<AuthInvitationPreview | null>;
193198
/** Accept an invitation as the current user */
194199
acceptInvitation: (invitationId: string) => Promise<void>;
195200
/** Reject an invitation as the current user */

0 commit comments

Comments
 (0)