Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1f91d99
test(mosaic): start and return from OAuth sign-ups in the fake FAPI
austincalvelage Nov 21, 2026
1b0d0cf
feat(mosaic): sign up with social providers
austincalvelage Nov 21, 2026
542692f
docs(mosaic): describe the sign-up OAuth return
austincalvelage Nov 21, 2026
0b31efc
chore(repo): add an empty changeset for social sign-up
austincalvelage Nov 21, 2026
930ffd1
feat(mosaic): ask for a required social provider on the sign-up conti…
austincalvelage Nov 21, 2026
3665f2f
test(mosaic): mirror FAPI's OAuth sign-up behavior more closely in th…
austincalvelage Nov 21, 2026
0354039
fix(mosaic): close the gaps a FAPI and legacy check found in social s…
austincalvelage Nov 21, 2026
125073c
docs(mosaic): correct the sign-up OAuth return and on-mount notes
austincalvelage Nov 21, 2026
ce7ec09
refactor(mosaic): keep the sign-up model under the complexity limit w…
austincalvelage Nov 23, 2026
19145ad
test(mosaic): show an invitee's denied Google sign-up without redeemi…
austincalvelage Nov 23, 2026
1e981e2
fix(mosaic): forget the invitation when a social sign-up comes back w…
austincalvelage Nov 23, 2026
e4a24e7
test(mosaic): complete a social sign-up return that opens on the cont…
austincalvelage Nov 23, 2026
e465f52
fix(mosaic): complete a social sign-up return on whichever route sign…
austincalvelage Nov 23, 2026
5d09478
refactor(mosaic): derive the sign-up OAuth return's busy state from i…
austincalvelage Nov 23, 2026
9c46c4f
test(mosaic): send the redirect_url as social sign-up's after-sign-up…
austincalvelage Nov 23, 2026
9549d0c
fix(mosaic): honor redirect_url as the URL a social sign-up lands on
austincalvelage Nov 23, 2026
a4d6e84
test(mosaic): send a social sign-up transfer that needs a second fact…
austincalvelage Nov 23, 2026
83c2d12
fix(mosaic): send a social sign-up transfer to the sign-in step it st…
austincalvelage Nov 23, 2026
144ef28
refactor(mosaic): move the sign-up OAuth completion out of the model …
austincalvelage Nov 23, 2026
23d3d2a
test(mosaic): cover social sign-up's existing session, Protect after …
austincalvelage Nov 23, 2026
41bb375
refactor(mosaic): share the redirect hold between sign-up and user pr…
austincalvelage Nov 23, 2026
9527fd2
docs(mosaic): describe the sign-up OAuth return as built
austincalvelage Nov 23, 2026
dc668bc
test(mosaic): cover a sign-up transfer after the Protect check on the…
austincalvelage Nov 23, 2026
8097999
fix(mosaic): transfer a social sign-up after its Protect check is solved
austincalvelage Nov 23, 2026
bf884b6
refactor(mosaic): read the sign-up OAuth return marker through the ro…
austincalvelage Nov 23, 2026
c9d16ef
test(mosaic): run a Protect check raised on the return from Google
austincalvelage Nov 23, 2026
5bf956e
refactor(mosaic): let the sign-up details controller decide which pro…
austincalvelage Nov 24, 2026
108f301
fix(mosaic): hide Continue's providers only when legal consent is all…
austincalvelage Nov 24, 2026
0706529
refactor(mosaic): settle the sign-up OAuth return inside completeReturn
austincalvelage Nov 24, 2026
34b5748
test(mosaic): land on the redirect_url when a social sign-up turns in…
austincalvelage Nov 24, 2026
e598d11
fix(mosaic): keep redirect_url when a social sign-up turns into a sig…
austincalvelage Nov 24, 2026
ed10065
docs(mosaic): say sign-up OAuth is a full-page redirect and popup OAu…
austincalvelage Nov 24, 2026
c18b608
test(mosaic): show the blocked notice when a social sign-up return wa…
austincalvelage Nov 24, 2026
dbaa2bb
fix(mosaic): show the blocked notice when a social sign-up return was…
austincalvelage Nov 24, 2026
484e97b
test(mosaic): show the blocked notice when starting a social sign-up …
austincalvelage Nov 24, 2026
4fd1a6a
fix(mosaic): show the blocked notice when starting a social sign-up i…
austincalvelage Nov 24, 2026
bd0cf5a
test(mosaic): give the social sign-up tests their own file
austincalvelage Nov 25, 2026
991d0d1
style(mosaic): sort imports in the sign-up details controller
austincalvelage Nov 25, 2026
14ee7b0
docs(mosaic): stop citing a TODO that sign-up does not have
austincalvelage Nov 30, 2026
f3c022f
refactor(mosaic): complete the sign-up OAuth return from the activity…
austincalvelage Dec 2, 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-oauth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
1 change: 1 addition & 0 deletions packages/mosaic/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Most problems a feature hits already have a shared answer. Find the line for you
- Moving focus after a list row is removed → `useListRemovalFocus` (`src/hooks/`)
- A debounced, abortable async check as the user types → `useDebouncedAsync` (`src/hooks/`)
- A spinner that should not flash or flicker → `useSpinDelay` (`src/hooks/`)
- Keeping an action pending after it starts a full-page redirect, such as to an OAuth provider → `REDIRECT_HOLD_MS` (`src/utils/redirect.ts`)
- A placeholder for content that is still loading → `Skeleton` (`src/components/skeleton/`), see [Skeletons](docs/skeletons.md)
- A date shown to the user → `formatDate` (`src/utils/format-date.ts`)
- Any current time read during render → `useNow` (`src/hooks/`), with `until` to stop ticking at a deadline
Expand Down
23 changes: 17 additions & 6 deletions packages/mosaic/docs/internals/sign-in-sign-up-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FAPI tracks which requirements are outstanding and whether a code has been sent.

Today FAPI sends `status`, `missing_fields` and `unverified_fields`, not a step. Until it sends `nextStep`, `getSignInNextStep` and `getSignUpNextStep` in `shared` compute it from those fields (see [Bridge](#bridge)).

Sign-up's `continue` screen asks for what FAPI lists in `missing_fields`, not for what the instance's settings would require, so the client never re-derives a rule FAPI already applied (`continueFields` in `mosaic/src/features/sign-up/sign-up.utils.ts`). A missing email, phone or username that FAPI also lists in `optional_fields` is a choice, so the form asks for one of them, with the email/phone switch when both are allowed. An email or phone FAPI lists in `unverified_fields` stays on the form, prefilled, so Edit on a verify screen reached from `continue` has an address to change. FAPI drops the old verification whenever an update sends the address, changed or not, so the verify screen sends a new code. Requirements another step owns, such as `enterprise_sso`, don't appear. When FAPI lists a requirement `continue` can't ask for, such as a required `oauth_*` provider, the step is `unknown` and the user sees Start over instead of a form that can't finish. A sign-up that must verify its email on an instance that enables the email link is `unknown` too, until the link screen is built; `ui` shows its link card there (`ui/src/components/SignUp/SignUpVerifyEmail.tsx`). `start` has no sign-up yet, so it reads the instance's settings.
Sign-up's `continue` screen asks for what FAPI lists in `missing_fields`, not for what the instance's settings would require, so the client never re-derives a rule FAPI already applied (`continueFields` in `mosaic/src/features/sign-up/sign-up.utils.ts`). A missing email, phone or username that FAPI also lists in `optional_fields` is a choice, so the form asks for one of them, with the email/phone switch when both are allowed. An email or phone FAPI lists in `unverified_fields` stays on the form, prefilled, so Edit on a verify screen reached from `continue` has an address to change. FAPI drops the old verification whenever an update sends the address, changed or not, so the verify screen sends a new code. Requirements another step owns, such as `enterprise_sso`, don't appear. A missing `oauth_*` provider shows that provider's button, and only the missing ones, since another provider can't satisfy it; the user links the rest from their profile. When FAPI lists a requirement `continue` can't ask for, such as a provider that can't sign the user in, the step is `unknown` and the user sees Start over instead of a form that can't finish. A sign-up that must verify its email on an instance that enables the email link is `unknown` too, until the link screen is built; `ui` shows its link card there (`ui/src/components/SignUp/SignUpVerifyEmail.tsx`). `start` has no sign-up yet, so it reads the instance's settings.

There is no step machine and no local copy of the step. What the step can't say lives in the route, such as the factor the user picked in `factorOne`'s `:factor` param, or whether a sign-up verify screen was reached from `continue`.

Expand Down Expand Up @@ -56,9 +56,9 @@ submitPassword: async (password: string) => {
```

- `complete`: the model's `finalize()`, then leave the flow for the after sign-up URL, which honors `redirect_url` and the redirect query params (`clerk.buildAfterSignUpUrl({ params })`). Creating the session clears the sign-up. Sign-up renders the model it left from while `finalize()` runs, and after it until a task that continues in the flow has its data loaded, so the task replaces the screen with no skeleton between them. It keeps the action pending throughout, the way the switcher holds its `frozenModel` ([Controllers → Wrapping actions](../controllers.md#wrapping-actions)). Once the hold ends with the session signed in, the flow is over: if the host keeps the component mounted, it renders nothing. In a modal, don't `close()` when the flow leaves: `finalize()`'s navigation is the last write and takes the modal with it.
- `transfer`: planned, not built. From sign-in, the model's `transfer()` will call `signUp.create({ transfer: true, unsafeMetadata })`, then `next` with the sign-up's step; a sign-in with sign-up built in holds the sign-up routes under `create/`, otherwise it leaves for the sign-up page. From sign-up, when the identifier already has an account, it will call `signIn.create({ transfer: true })`, then `next` with the sign-in's step. Until then sign-up keeps the current screen on a `transfer` step.
- `transfer`: sign-up transfers only an OAuth account that already has a user. The OAuth return transfers it before a step reaches `next` ([Entry actions](#entry-actions)), unless a Protect check comes first. Then the Protect screen passes `transfer` to `next`, which runs the return's completion again and shows the loading screen while it does. Sign-in's transfer is planned: the model's `transfer()` will call `signUp.create({ transfer: true, unsafeMetadata })`, then `next` with the sign-up's step; a sign-in with sign-up built in holds the sign-up routes under `create/`, otherwise it leaves for the sign-up page.
- `unknown`: nothing. The screen already shows "Start over".
- `blocked`: sign-up's `create`, the Protect proof's `resolve` and the invitation's `redeemTicket` resolve with it, not a step, when FAPI answers `action_blocked`. The controller keeps the details for this mount and shows the notice in place of `start` or the Protect route. The notice is not read from Clerk's sign-up error, which outlives the component, so a remount shows the form again, as `ui`'s card error does.
- `blocked`: sign-up's `create`, the Protect proof's `resolve` and the invitation's `redeemTicket` resolve with it, not a step, when FAPI answers `action_blocked`. The OAuth return's `completeReturn` resolves with it when FAPI stored that error on the external account, and `sso` resolves with it from `start`. From `continue`, `sso` rejects and the error shows inline, as `update`'s does. The controller keeps the details for this mount and shows the notice in place of `start` or the Protect route. The notice is not read from Clerk's sign-up error, which outlives the component, so a remount shows the form again, as `ui`'s card error does.
- Anything else: `go(routeFor(step))`.
- An error from `finalize()` or the transfer stays on the current screen until the user leaves it, so Edit clears it. After an invitation that completed on redemption, that screen is `start` ([Entry actions](#entry-actions)). A sign-up that is already complete skips the request and returns `complete`, so entering the code again, or pressing Continue again on `start` or `continue`, runs `finalize()` again. Sending the request again would fail: the user now exists, so FAPI answers `form_identifier_exists`.

Expand Down Expand Up @@ -111,7 +111,7 @@ With no `:factor`, `factorOne` starts on the factor `ui`'s `determineStartingSig

## Entry actions

Sign-up redeems invitation tickets. The other entries are planned. The controller records why the visitor arrived when sign-up opens (`arrival.intent`), and that intent picks the activity machine's first state. Each entry is that state's `invoke`, which calls the model callback and then `next(step)`, so it runs once.
Sign-up redeems invitation tickets and completes OAuth returns. The other entries are planned. The controller records why the visitor arrived when sign-up opens (`arrival.intent`), and that intent picks the activity machine's first state. Each entry is that state's `invoke`, which calls the model callback and then `next(step)`, so it runs once.

- Ticket:
- Read and redeem once. Sign-up reads the ticket from `__clerk_ticket` or `__clerk_invitation_token`, as `ui`'s `SignUpStart` does, redeems it with `signUp.ticket({ unsafeMetadata })`, and shows the loading screen while it redeems. Sign-up redeems when it opens on `start`, or when the route guard sends it there. A ticket works only once, and the machine's `redeemingTicket` state runs the redemption once, so StrictMode can't redeem it twice. A failed redemption shows its error on `start` and removes the parameters, so `start` then works as a normal sign-up. A blocked redemption removes them too and shows `actionBlocked`.
Expand All @@ -120,8 +120,19 @@ Sign-up redeems invitation tickets. The other entries are planned. The controlle
- An invitation that needs nothing more. FAPI can answer the redemption with `complete`. The model does not pick the loading screen, so freezing the model alone would show `start` while `finalize()` runs. `FINALIZE` sent from `redeemingTicket` freezes the loading screen with the model, since arrival work has no screen of its own, and it stays up through `finalize()` and the wait for a task. If `finalize()` fails, the hold ends and `start` shows the error. `finalize()` has removed the ticket by then, so `start` is a normal sign-up form with its sign-in link.
- Cleanup, and what waits for sign-in. Finishing or starting over removes the parameters. Choosing between `signUp.ticket()` and `signIn.ticket()` by `__clerk_status`, as `ui/src/components/SignIn/SignInStart.tsx` does, is sign-in's job and waits for its controller.
- Email-link return (`__clerk_status`): `verified` with a `__clerk_created_session` this client has activates that session (`clerk-js/src/core/clerk.ts:2620-2636`); any other `verified` continues by step. `transferable` and the error statuses show their own screen, as `ui/src/common/EmailLinkVerify.tsx` does.
- Redirect URLs for email links and OAuth/SAML returns come from the router (the planned `useReturnUrl(name, params)`), never hand-built. That part waits for the routing follow-up.
- A step that is already `complete` or `transfer` on mount, such as a reload before it ran: `next(step)` runs it once, from an arrival state like the ticket's. The email-link return is handled first.
- Redirect URLs for email links and OAuth/SAML returns will come from the router's `useReturnUrl(name, params)` (#10860). For now the OAuth return builds its callback URL by hand with a marker, described in the next entry. The marker moves to `useReturnUrl()` when that hook lands.
- OAuth return: sign-up's callback URL is the current URL plus the marker `__clerk_mosaic_sign_up=sso-callback`, the way `withUserProfileModalReturn` marks a profile return. It keeps the rest of the query, so `redirect_url` and an invitation's ticket come back with the user. `sso()` sends the after sign-up URL that honors `redirect_url` as the URL to land on after the provider. When sign-up opens with the marker, on any route, the arrival intent is `return`, so the activity machine starts in `completingReturn`: the loading screen shows from the first paint and the state's `invoke` runs `completeReturn` once. A transfer after a solved Protect check sends `COMPLETE_RETURN` to the same state. The ticket waits until the return is done, and the machine moves to `redeemingTicket` if sign-up is then on `start` with a ticket that isn't its own. `completeReturn` removes the marker and follows `clerk.handleRedirectCallback`'s sign-up branches on the Future API:
- A Protect check comes first. Once it is solved, `next` gets the step that follows, so a transfer after it still runs.
- A `transferable` account becomes a sign-in (`signIn.create({ transfer: true })`). A complete sign-in finishes in place. Otherwise the user goes to the sign-in route its status needs, as `_handleRedirectCallback` does: `factor-one`, `factor-two`, `reset-password`, or `protect-check` when the sign-in has a Protect check. The route goes in the hash of the sign-in URL, which keeps `redirect_url`.
- An `identifier_already_signed_in` account activates that session.
- A session from a transfer or an existing session is a sign-in, so a pending task goes to its task URL rather than staying in sign-up.
- An external-account error removes the ticket, resets the sign-up and shows on `start`, with FAPI's message only for the codes legacy's `SignUpStart` shows and the generic error otherwise. An `action_blocked` error that carries its details resolves with `blocked` instead and shows `actionBlocked`, as legacy's `ActionBlockedCard` does. Removing the ticket keeps the invitation from being redeemed again over the error, as in legacy, where the callback URL has no ticket.
- Anything else is `next(step)`.

The marker is gone once the return starts, so a reload mid-return lands on `start`. OAuth is a full-page redirect only. Sign-up never passes `sso()` a `popup`, so popup OAuth (`oauthFlow: 'popup'`) is not built. An OAuth transport (`__internal_oauthTransport`) is not supported yet. `SignUpFuture.sso()` still navigates the window, so clerk-js has to honor the transport first. Sign-in-to-sign-up transfers start from sign-in, so they wait for its controller.

- `signUp.sso()` updates any sign-up already on the client, so `start` resets a sign-up that isn't the invitation's and calls `sso()` on the client's new sign-up, since the old `SignUpFuture` still points at the reset one; `continue` keeps it. On an instance with no form identifier, where `showFormFields` is false, `start` shows only the providers, without fields or the consent checkbox, as legacy does; consent then comes on `continue`. `continue` hides the providers once the sign-up has a verified external account.
- A step that is already `complete` or `transfer` on mount, such as a reload before it ran, is not handled yet: `routeFor` has no route for `transfer`, and nothing runs `complete` when sign-up mounts. The email-link return will be handled first.
- Hash params: Clerk's URL builders (`redirectToSignUp()`, `buildSignUpUrl`) put the redirect params and initial values in the URL hash, and sign-up reads only the query, so they are not read yet.

## Bridge
Expand Down
Loading
Loading