Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
617c9ff
feat(mosaic): send sign-up phone codes over WhatsApp
austincalvelage Nov 19, 2026
2b9c51a
chore(repo): add an empty changeset for sign-up WhatsApp codes
austincalvelage Nov 20, 2026
d94e946
test(mosaic): resend the sign-up phone code over WhatsApp
austincalvelage Nov 20, 2026
d3afbc0
fix(mosaic): close the WhatsApp sign-up parity gaps
austincalvelage Nov 20, 2026
34aeba5
test(mosaic): check WhatsApp in the fake FAPI the way FAPI does
austincalvelage Nov 20, 2026
26caa00
fix(mosaic): close the gaps a FAPI and legacy check found in WhatsApp…
austincalvelage Nov 20, 2026
9d2204d
test(mosaic): wait for the SMS code before ending the WhatsApp switch…
austincalvelage Nov 21, 2026
8c54054
test(mosaic): send the WhatsApp sign-up code in the create request
austincalvelage Nov 23, 2026
f288039
fix(mosaic): send the sign-up phone channel in the create request
austincalvelage Nov 23, 2026
885c5c6
test(mosaic): check phone errors stay on the sign-up screen that got …
austincalvelage Nov 23, 2026
15d244c
fix(mosaic): keep phone errors on the sign-up screen that got them
austincalvelage Nov 23, 2026
c95a7ff
test(mosaic): resend the sign-up phone code by SMS after switching fr…
austincalvelage Nov 23, 2026
27e5e4c
test(mosaic): keep the sign-up a failed WhatsApp send leaves behind
austincalvelage Nov 23, 2026
7ae608a
test(mosaic): drop WhatsApp sign-up tests that repeat another test
austincalvelage Nov 24, 2026
b536d57
test(mosaic): import vi for the WhatsApp resend countdown tests
austincalvelage Nov 24, 2026
95a89e8
test(mosaic): import act for the WhatsApp sign-up tests
austincalvelage Nov 24, 2026
b36b6d5
refactor(mosaic): give the sign-up switch to SMS its own sending state
austincalvelage Nov 24, 2026
dd897e7
test(mosaic): group the sign-up phone channel tests and seed their si…
austincalvelage Nov 24, 2026
2ff4ec9
fix(mosaic): clear a form error when sign-up switches between the pho…
austincalvelage Nov 24, 2026
cf03f20
docs(mosaic): note why the sign-up phone channel screen has no route
austincalvelage Nov 24, 2026
93cbd73
docs(mosaic): say why a sign-up phone channel switch resets the form
austincalvelage Nov 24, 2026
80ac91e
refactor(mosaic): send sign-up details with one create call and drop …
austincalvelage Nov 24, 2026
424c054
test(mosaic): expect a wrong WhatsApp code error to clear when sendin…
austincalvelage Nov 24, 2026
b3c1762
fix(mosaic): clear a wrong code error when sign-up sends the code by …
austincalvelage Nov 24, 2026
ed2ce5b
test(mosaic): show the blocked notice when a WhatsApp sign-up is blocked
austincalvelage Nov 24, 2026
7cfceae
test(mosaic): give the sign-up phone channel tests their own file
austincalvelage Nov 25, 2026
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
2 changes: 2 additions & 0 deletions .changeset/mosaic-sign-up-whatsapp-codes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
3 changes: 2 additions & 1 deletion packages/mosaic/docs/internals/sign-in-sign-up-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Sign-up renders one component per screen, so the route decides what is mounted (
- A screen with work to do on arrival owns its controller. `SignUpVerify` holds the code machine and sends the code when it mounts on a step with `sent: false`. A submit, a reload and a redirect all arrive that way. A screen that runs a controller reaches the view as a slot the wrapper builds, as the profile section's `nameAction` does, so `SignUpView` renders plain props only.
- `SignUpVerify` takes the sign-up's id as its `key`, so a new sign-up never reuses the last one's screen.
- A screen another feature owns arrives as a slot. The wrapper runs the task's model once, passes it to `TaskChooseOrganizationContent` (the task without its card), and tells the controller whether the task has loaded. The view mounts the slot on the task route.
- A screen that is not a route sits on top of one. `restricted` and `waitlist` replace `start`, `actionBlocked` replaces `start` and the Protect routes, and `startOver` replaces any route. A route whose screen is not built yet (`enterpriseConnections`) shows `startOver`.
- A screen that is not a route sits on top of one. `restricted` and `waitlist` replace `start`, `alternativePhone` replaces `start` while the user has picked a phone channel such as WhatsApp there, `actionBlocked` replaces `start` and the Protect routes, and `startOver` replaces any route. A route whose screen is not built yet (`enterpriseConnections`) shows `startOver`.
- The channel `alternativePhone` shows is state in `useSignUpDetailsController`, not a route. The user picks it on the start form before any sign-up exists, the screen edits that same form, and no step `getSignUpNextStep` returns leads to it, so there is nothing for a route to restore. Use another method on that screen and Edit on the code screen both clear it.

## Move on after a submit

Expand Down
98 changes: 67 additions & 31 deletions packages/mosaic/src/__tests__/feature/fake-fapi/sign-up.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import type { ClientJSON, SessionJSON, SignUpField, SignUpIdentificationField, SignUpJSON } from '@clerk/shared/types';
import type {
ClientJSON,
PhoneCodeChannel,
SessionJSON,
SignUpField,
SignUpIdentificationField,
SignUpJSON,
} from '@clerk/shared/types';
import { http, HttpResponse } from 'msw';

import {
Expand Down Expand Up @@ -27,6 +34,8 @@ export interface FakeSignUpSeed {
protectCheckResolvedElsewhere?: boolean;
protectCheckBlocked?: Record<string, string>;
protectCheckScript?: string;
whatsAppEnabled?: boolean;
whatsAppQuotaExceeded?: boolean;
}

export interface FakeSignUpState {
Expand All @@ -41,6 +50,8 @@ export interface FakeSignUpState {
protectCheckResolvedElsewhere?: boolean;
protectCheckBlocked?: Record<string, string>;
protectCheckScript?: string;
whatsAppEnabled: boolean;
whatsAppQuotaExceeded: boolean;
issuedProtectChecks: number;
reloads: number;
proofTokens: string[];
Expand All @@ -56,6 +67,8 @@ export function createSignUpState(seed: FakeSignUpSeed = {}): FakeSignUpState {
sessionTasks: null,
weakPasswords: {},
protectChecks: 0,
whatsAppEnabled: true,
whatsAppQuotaExceeded: false,
issuedProtectChecks: 0,
reloads: 0,
proofTokens: [],
Expand Down Expand Up @@ -326,6 +339,47 @@ export function signUpHandlers(
return next;
};

const prepare = (signUp: SignUpJSON, body: URLSearchParams): SignUpJSON | ReturnType<typeof rejected> => {
const strategy = body.get('strategy') ?? '';
const channel = body.get('channel');
const field = STRATEGIES[strategy];
const attribute = field ? settings().attributes[field] : undefined;
if (!field || !attribute?.verifications.some(supported => supported === strategy)) {
return rejected('form_param_value_invalid', `${strategy} does not match one of the allowed values.`, 'strategy');
}
if (!signUp[field]) {
return rejected('form_param_missing', `${field} must be set before it can be verified.`, field);
}
if (signUp.verifications?.[field].status === 'verified') {
return rejected('verification_already_verified', 'This verification has already been verified.', undefined, 400);
}
const isPhone = field === 'phone_number';
if (isPhone && channel && channel !== 'sms' && channel !== 'whatsapp') {
return rejected('form_param_value_invalid', `${channel} does not match one of the allowed values.`, 'channel');
}
if (isPhone && channel === 'whatsapp' && !state.signUp.whatsAppEnabled) {
return rejected(
'whatsapp_channel_not_enabled',
"The 'whatsapp' channel is not available for this instance.",
'channel',
);
}
const sentOver = channel === 'whatsapp' && state.signUp.whatsAppQuotaExceeded ? 'sms' : (channel ?? 'sms');
state.signUp.preparations.push(isPhone && channel ? `${strategy}:${channel}` : strategy);
return {
...signUp,
verifications: {
...signUp.verifications!,
[field]: {
...signUp.verifications![field],
...fapiVerification(strategy),
next_action: 'needs_attempt',
channel: isPhone ? (sentOver as PhoneCodeChannel) : undefined,
},
},
};
};

if (state.client.sign_up) {
state.client = { ...state.client, sign_up: settle(state.client.sign_up) };
}
Expand All @@ -342,7 +396,16 @@ export function signUpHandlers(
}
const blank = fapiSignUp({ id: `sua_${state.signUp.creations.length}` });
const applied = apply(blank, body);
return applied instanceof HttpResponse ? applied : store(settle(issueProtectCheck(applied)));
if (applied instanceof HttpResponse) {
return applied;
}
const created = issueProtectCheck(applied);
const prepared = body.get('strategy') === 'phone_code' ? prepare(created, body) : created;
if (prepared instanceof HttpResponse) {
store(settle(created));
return clientError(prepared);
}
return store(settle(prepared));
}),
http.get(fapiUrl('/protect-check/challenge.js'), () =>
HttpResponse.text(state.signUp.protectCheckScript ?? PROTECT_CHECK_SCRIPT, {
Expand Down Expand Up @@ -410,35 +473,8 @@ export function signUpHandlers(
if (!signUp?.verifications) {
return missing();
}
const strategy = new URLSearchParams(await request.text()).get('strategy') ?? '';
const field = STRATEGIES[strategy];
const attribute = field ? settings().attributes[field] : undefined;
if (!field || !attribute?.verifications.some(supported => supported === strategy)) {
return rejected(
'form_param_value_invalid',
`${strategy} does not match one of the allowed values.`,
'strategy',
);
}
if (!signUp[field]) {
return rejected('form_param_missing', `${field} must be set before it can be verified.`, field);
}
if (signUp.verifications[field].status === 'verified') {
return rejected(
'verification_already_verified',
'This verification has already been verified.',
undefined,
400,
);
}
state.signUp.preparations.push(strategy);
return store({
...signUp,
verifications: {
...signUp.verifications,
[field]: { ...signUp.verifications[field], ...fapiVerification(strategy), next_action: 'needs_attempt' },
},
});
const prepared = prepare(signUp, new URLSearchParams(await request.text()));
return prepared instanceof HttpResponse ? prepared : store(prepared);
}),
http.post(fapiUrl('/v1/client/sign_ups/:id/attempt_verification'), async ({ params, request }) => {
const signUp = current(params.id);
Expand Down
Loading
Loading