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
19 changes: 19 additions & 0 deletions .changeset/34706-accept-invitation-followups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@objectstack/platform-objects': patch
'@object-ui/app-shell': patch
'@object-ui/console': patch
'@object-ui/i18n': patch
---

fix(app-shell,console): the invitation inbox's accept routes an unverified address to verification, and the verify screen no longer says a link was sent before it was

Clause-②: no
Metadata-protocol: none

Follow-ups to the rule that, while a deployment delivers mail, accepting an invitation needs a verified address (`403 EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION`).

- **The invitation inbox's Accept** (`@object-ui/app-shell`). When the `sys_invitation` `accept_invitation` action is refused with that code, the console's `type: 'api'` action handlers (`useConsoleActionRuntime` and `RecordDetailView`, through the action door or the direct call alike) now open the verification-mail screen, `/verify-email-prompt`, for the account's address, with the mail's link returning to that invitation's accept page, instead of showing the vendor's sentence in a toast. Every other refusal still reads as before. The rule is keyed on the code alone; no action metadata key, spec field or server route changes.
- **The action's AI description** (`@objectstack/platform-objects`). `sys_invitation.accept_invitation`'s `ai.description` now states the condition: while the deployment delivers email, the caller's address must be verified, and an unverified caller is refused with that code and nothing is written. The text is the agent-facing description only; no translated bundle carries it.
- **The verify screen's copy** (`@object-ui/console`, `@object-ui/i18n`). `/verify-email-prompt` said "We sent a verification link" on every arrival, but only the sign-up sends a mail before arriving there. The sign-in arrival (refused `EMAIL_NOT_VERIFIED`, which sends nothing unless the deployment sets `emailVerification.sendOnSignIn`) and both accept-invitation arrivals send nothing. The sign-up arrival now marks itself with `?sent=1` and keeps its copy; every other arrival reads "Your email address has not been verified yet. Send a verification link to ADDRESS…", offers "Send verification email", and shows "Sent to:" and the spam hint only once the button has sent the mail. Two keys are added to the `auth.verifyEmail` namespace in every built-in locale: `sendDescription` and `sendButton`.

**A host that embeds the accept page or the console action runtime declares `/verify-email-prompt`.** `DefaultAcceptInvitationPage` and the action handlers above navigate there with `email` and `redirect` query keys; `apps/console` mounts its own `VerifyEmailPromptPage` at that route, and a host without it sends the person to a route that does not exist. The `@object-ui/app-shell` README states the route and its query keys ("Hosting the invitation pages").
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ export const SysInvitation = ObjectSchema.create({
ai: {
exposed: true,
description:
'Accept an invitation addressed to the current user (the record), joining its organization with the invited role. Works only on a pending invitation sent to the caller\'s own email address.',
'Accept an invitation addressed to the current user (the record), joining its organization with the invited role. Works only on a pending invitation sent to the caller\'s own email address. '
+ 'While this deployment delivers email, the caller\'s address must also be verified: an unverified caller is refused with EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION and nothing is written, so ask the human to verify their email address first, then accept.',
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions ui/apps/console/src/pages/auth/RegisterPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
import { AuthLayout } from './AuthLayout';
import { followOauthAuthorize } from './followAuthorize';
import { handoffMarkQuery, useHandoffRedirect, verificationCallbackURL } from './handoffRedirect';
import { VERIFICATION_SENT_PARAM } from './verifyEmailPromptQuery';
// Was a second module-private copy of LoginPage's helper; both now share one
// implementation — objectui#4181. Behaviour here is unchanged.
import { withConsoleBase } from '../../utils/consoleBase';
Expand Down Expand Up @@ -423,6 +424,8 @@ export function RegisterPage() {
const sp = new URLSearchParams();
sp.set('email', email);
if (redirect) sp.set('redirect', redirect);
// The sign-up has sent the verification mail (objectstack#34706).
sp.set(VERIFICATION_SENT_PARAM, '1');
navigate(`/verify-email-prompt?${sp.toString()}${handoffMarkQuery(redirect)}`, { replace: true });
}}
labels={{
Expand Down
55 changes: 39 additions & 16 deletions ui/apps/console/src/pages/auth/VerifyEmailPromptPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/**
* VerifyEmailPromptPage — "we sent you a link" page shown after sign-up
* or after a sign-in attempt was blocked by `EMAIL_NOT_VERIFIED`.
* VerifyEmailPromptPage — the verification-mail page shown after sign-up,
* after a sign-in attempt was blocked by `EMAIL_NOT_VERIFIED`, and after an
* invitation accept was refused for an unverified address.
*
* Only the sign-up arrival has had a mail sent for it, and only it says so
* (`?sent=1`, `./verifyEmailPromptQuery`). Every other arrival asks the person
* to send the link and reads "sent" only once the button has sent it
* (objectstack#34706).
*
* Ported from `framework/apps/account/src/routes/verify-email-prompt.tsx`.
* Calls `useAuth().sendVerificationEmail(email, callbackURL)` on resend.
Expand All @@ -22,13 +28,16 @@ import {
} from '@object-ui/components';
import { AuthLayout } from './AuthLayout';
import { handoffMarkQuery, verificationCallbackURL } from './handoffRedirect';
import { VERIFICATION_SENT_PARAM } from './verifyEmailPromptQuery';

export function VerifyEmailPromptPage() {
const { t } = useObjectTranslation();
const navigate = useNavigate();
const [params] = useSearchParams();
const email = params.get('email') ?? '';
const redirect = params.get('redirect') ?? '';
// Did this arrival's server call already send the mail? Only the sign-up's.
const sentOnArrival = params.get(VERIFICATION_SENT_PARAM) === '1';
const { sendVerificationEmail } = useAuth();

const [resending, setResending] = useState(false);
Expand Down Expand Up @@ -112,15 +121,23 @@ export function VerifyEmailPromptPage() {
{t('auth.verifyEmail.title', { defaultValue: 'Verify your email address' })}
</CardTitle>
<CardDescription>
{t('auth.verifyEmail.description', {
defaultValue:
'We sent a verification link to your email address. Please click the link to verify your account.',
})}
{sentOnArrival
? t('auth.verifyEmail.description', {
defaultValue:
'We sent a verification link to your email address. Please click the link to verify your account.',
})
: email
? t('auth.verifyEmail.sendDescription', {
email,
defaultValue:
'Your email address has not been verified yet. Send a verification link to {{email}}, then click the link to verify your account.',
})
: t('auth.verifyEmail.emailMissing', { defaultValue: 'Email address is missing' })}
</CardDescription>
</CardHeader>
<CardContent>
<div className="flex flex-col gap-4">
{email ? (
{email && (sentOnArrival || resent) ? (
<p className="text-center text-sm text-muted-foreground">
{t('auth.verifyEmail.sentTo', { defaultValue: 'Sent to:' })}{' '}
<span className="font-medium text-foreground">{email}</span>
Expand Down Expand Up @@ -159,9 +176,13 @@ export function VerifyEmailPromptPage() {
) : (
<>
<RefreshCw className="mr-2 size-4" />
{t('auth.verifyEmail.resendButton', {
defaultValue: 'Resend verification email',
})}
{sentOnArrival
? t('auth.verifyEmail.resendButton', {
defaultValue: 'Resend verification email',
})
: t('auth.verifyEmail.sendButton', {
defaultValue: 'Send verification email',
})}
</>
)}
</Button>
Expand All @@ -181,12 +202,14 @@ export function VerifyEmailPromptPage() {
{t('auth.verifyEmail.backToLogin', { defaultValue: 'Back to login' })}
</Button>

<p className="text-center text-xs text-muted-foreground">
{t('auth.verifyEmail.checkSpam', {
defaultValue:
"Didn't receive the email? Check your spam folder or contact support.",
})}
</p>
{sentOnArrival || resent ? (
<p className="text-center text-xs text-muted-foreground">
{t('auth.verifyEmail.checkSpam', {
defaultValue:
"Didn't receive the email? Check your spam folder or contact support.",
})}
</p>
) : null}
</div>
</CardContent>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,16 @@ function renderPage(page: keyof typeof PAGES, client: AuthClient, search: string
const withRedirect = (redirect: string) => `?redirect=${encodeURIComponent(redirect)}`;
const routerLocation = () => screen.getByTestId('router-location').textContent;

/** The prompt's query as `/login` and `/register` build it today: `email`, then `redirect`. */
const promptAt = (redirect: string) => {
/**
* The prompt's query as `/login` and `/register` build it today: `email`, then
* `redirect`, then — from `/register` alone, whose sign-up sent the mail —
* `sent` (objectstack#34706).
*/
const promptAt = (redirect: string, sent = false) => {
const sp = new URLSearchParams();
sp.set('email', EMAIL);
sp.set('redirect', redirect);
if (sent) sp.set('sent', '1');
return `/verify-email-prompt?${sp.toString()}`;
};

Expand Down Expand Up @@ -151,7 +156,7 @@ describe('the verification mail returns a hand-off sign-up to "go back to the ap

it('/verify-email-prompt: the resent mail', async () => {
const client = createMockClient();
renderPage('verify-email-prompt', client, `?email=${encodeURIComponent(EMAIL)}&redirect=${encodeURIComponent(HANDOFF)}`);
renderPage('verify-email-prompt', client, `?email=${encodeURIComponent(EMAIL)}&redirect=${encodeURIComponent(HANDOFF)}&sent=1`);
await userEvent.click(await screen.findByRole('button', { name: /Resend verification email/ }));
await waitFor(() => expect(client.sendVerificationEmail).toHaveBeenCalledTimes(1));
expect(client.sendVerificationEmail.mock.calls[0]).toEqual([EMAIL, '/_console/verify-email?handoff=verified']);
Expand All @@ -162,7 +167,7 @@ describe('the verification mail returns a hand-off sign-up to "go back to the ap
await signUpUnverified(client, INVITE, MARK);
expect(client.signUp.mock.calls[0][0].callbackURL).toBe('/_console/accept-invitation/inv_1');
cleanup();
renderPage('verify-email-prompt', client, `?email=${encodeURIComponent(EMAIL)}&redirect=${encodeURIComponent(INVITE)}`);
renderPage('verify-email-prompt', client, `?email=${encodeURIComponent(EMAIL)}&redirect=${encodeURIComponent(INVITE)}&sent=1`);
await userEvent.click(await screen.findByRole('button', { name: /Resend verification email/ }));
await waitFor(() => expect(client.sendVerificationEmail).toHaveBeenCalledTimes(1));
expect(client.sendVerificationEmail.mock.calls[0]).toEqual([EMAIL, '/_console/accept-invitation/inv_1']);
Expand All @@ -177,7 +182,7 @@ describe('the route\'s refusal time survives the hops through /verify-email-prom

it('/register: verification required carries it to the prompt', async () => {
await signUpUnverified(createMockClient(), HANDOFF, MARK);
expect(routerLocation()).toBe(`${promptAt(HANDOFF)}${MARK}`);
expect(routerLocation()).toBe(`${promptAt(HANDOFF, true)}${MARK}`);
});

it('/verify-email-prompt: "Back to login" carries it', async () => {
Expand All @@ -191,7 +196,7 @@ describe('the route\'s refusal time survives the hops through /verify-email-prom
expect(routerLocation()).toBe(promptAt(INVITE));
cleanup();
await signUpUnverified(createMockClient(), INVITE, MARK);
expect(routerLocation()).toBe(promptAt(INVITE));
expect(routerLocation()).toBe(promptAt(INVITE, true));
cleanup();
renderPage('verify-email-prompt', createMockClient(), `?redirect=${encodeURIComponent(INVITE)}${MARK}`);
await userEvent.click(await screen.findByRole('button', { name: 'Back to login' }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,15 @@ describe('RegisterPage — the verification mail carries ?redirect= (objectui#10
const sp = new URLSearchParams(window.location.search);
expect(sp.get('email')).toBe('wangwei@example.com');
expect(sp.get('redirect')).toBe('/accept-invitation/inv_1');
// objectstack#34706 — the sign-up sent the mail, and says so to the prompt.
expect(sp.get('sent')).toBe('1');
});
});

describe('VerifyEmailPromptPage — the resent mail carries ?redirect= too (objectui#10893)', () => {
async function resendCallback(name: MountName, search: string): Promise<[unknown, unknown]> {
const mount = mountConsole(name, `/verify-email-prompt${search}`);
// The resend after a sign-up, which marks its arrival as sent (objectstack#34706).
const mount = mountConsole(name, `/verify-email-prompt${search}&sent=1`);
renderAt(mount.basename, <VerifyEmailPromptPage />);
await userEvent.click(await screen.findByRole('button', { name: /Resend verification email/ }));
await waitFor(() => expect(wire.resend).toHaveLength(1));
Expand All @@ -208,3 +211,48 @@ describe('VerifyEmailPromptPage — the resent mail carries ?redirect= too (obje
expect(Object.keys(wire.resend[0])).not.toContain('callbackURL');
});
});

describe('VerifyEmailPromptPage — the standing copy says a link was sent only when one was (objectstack#34706)', () => {
const SENT_COPY = 'We sent a verification link to your email address. Please click the link to verify your account.';
const ADDRESS = 'wangwei@example.com';

function arriveAt(search: string) {
const mount = mountConsole('standalone', `/verify-email-prompt${search}`);
renderAt(mount.basename, <VerifyEmailPromptPage />);
}

// The sign-in arrival (`/login` on EMAIL_NOT_VERIFIED) and the accept-invitation
// arrivals carry `email` and `redirect` and no `sent`: nothing was mailed.
it('an arrival that sent nothing asks the person to send the link, and claims no mail before the button is pressed', async () => {
arriveAt(`?email=wangwei%40example.com&${INVITE.slice(1)}`);

expect(await screen.findByText(
`Your email address has not been verified yet. Send a verification link to ${ADDRESS}, then click the link to verify your account.`,
)).toBeTruthy();
expect(screen.getByRole('button', { name: /^Send verification email$/ })).toBeTruthy();
expect(screen.queryByText(SENT_COPY)).toBeNull();
expect(screen.queryByText(/Sent to:/)).toBeNull();
expect(screen.queryByText(/Didn't receive the email/)).toBeNull();
expect(wire.resend).toHaveLength(0);
});

it('pressing the button sends the mail, and only then does the page say it was sent', async () => {
arriveAt(`?email=wangwei%40example.com&${INVITE.slice(1)}`);
await userEvent.click(await screen.findByRole('button', { name: /^Send verification email$/ }));

await waitFor(() => expect(wire.resend).toHaveLength(1));
expect(wire.resend[0].email).toBe(ADDRESS);
expect(await screen.findByText(/Sent to:/)).toBeTruthy();
expect(screen.getByText(/Didn't receive the email/)).toBeTruthy();
expect(screen.getByRole('button', { name: 'Email sent! Check your inbox' })).toBeTruthy();
});

it('CONTROL: the sign-up arrival (`sent=1`) keeps its "we sent" copy and offers a resend', async () => {
arriveAt(`?email=wangwei%40example.com&${INVITE.slice(1)}&sent=1`);

expect(await screen.findByText(SENT_COPY)).toBeTruthy();
expect(screen.getByText(/Sent to:/)).toBeTruthy();
expect(screen.getByRole('button', { name: /^Resend verification email$/ })).toBeTruthy();
expect(screen.getByText(/Didn't receive the email/)).toBeTruthy();
});
});
14 changes: 14 additions & 0 deletions ui/apps/console/src/pages/auth/verifyEmailPromptQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* The query key an arrival at `/verify-email-prompt` sets when the server has
* already sent the verification mail (objectstack#34706).
*
* Only the sign-up arrival sets it: the sign-up sends the mail itself when it
* answers that verification is required. The sign-in arrival (a refused
* `EMAIL_NOT_VERIFIED`, which sends nothing unless the deployment opts into
* `emailVerification.sendOnSignIn`) and the accept-invitation arrivals (a
* refused accept, which sends nothing) leave it out, so the prompt's standing
* copy asks the person to send the link rather than saying it was sent.
* Absent is the default on purpose: a page that cannot tell must not claim a
* mail went out.
*/
export const VERIFICATION_SENT_PARAM = 'sent';
22 changes: 22 additions & 0 deletions ui/packages/app-shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,28 @@ invitation redirect is an
affordance, not an authorization: the server still refuses a non-invitee's
sign-up.

### Hosting the invitation pages: declare `/verify-email-prompt`

While a deployment delivers mail, the server refuses to let an account whose
address is not verified accept an invitation
(`EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION`). Two
surfaces of this package answer that refusal by navigating to the
verification-mail screen at `/verify-email-prompt`, a route this package does
not mount:

- `DefaultAcceptInvitationPage` (`/accept-invitation/:invitationId`), with
`redirect` set to the accept page itself;
- the console's `type: 'api'` action handlers (`useConsoleActionRuntime` and
`RecordDetailView`), when the invitation inbox's `accept_invitation` action
is refused, with `redirect` set to the accept page for that invitation.

A host that mounts either one declares `/verify-email-prompt` too, or the
person is sent to a route that does not exist. The route reads two query keys,
each absent when unknown: `email`, the account's address, and `redirect`, the
basename-stripped router path the verification mail's link returns to. Nothing
has been sent when either surface arrives there, so the screen offers to send
the link. `apps/console` mounts its own `VerifyEmailPromptPage` there.

## Unsaved edits

A page that keeps edits in component state registers them while it holds them,
Expand Down
Loading
Loading