Skip to content

feat(mosaic): sign up with social providers - #10945

Draft
austincalvelage wants to merge 38 commits into
austin/mosaic-sign-up-invitationsfrom
austin/mosaic-sign-up-oauth
Draft

austincalvelage wants to merge 38 commits into
austin/mosaic-sign-up-invitationsfrom
austin/mosaic-sign-up-oauth

Conversation

@austincalvelage

@austincalvelage austincalvelage commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Description

Adds social (OAuth) sign-up to Mosaic. Stacked on #10944.

Review fixes

  • A return with a provider error forgets the invitation ticket, so the ticket isn't redeemed again and the error stays on screen. A successful return keeps the ticket. fix(mosaic): forget the invitation when a social sign-up comes back with an error, covered by "keeps the denial on screen when an invitee comes back from Google, and does not redeem the ticket again".
  • The return completes on whichever route sign-up opens, not only start. fix(mosaic): complete a social sign-up return on whichever route sign-up opens, covered by "completes the return when sign-up opens on the continue route".
  • The loading screen reads the marker until the return action has run, then the action's pending state, so busy has one source. refactor(mosaic): derive the sign-up OAuth return's busy state from its pending action and refactor(mosaic): read the sign-up OAuth return marker through the router, which reads the marker through the router. Covered by the return tests.
  • sso() sends the after sign-up URL that honors redirect_url as the URL to land on. fix(mosaic): honor redirect_url as the URL a social sign-up lands on, covered by "starts Google sign-up with a callback URL that brings the user back to sign-up, then on to $landing".
  • A transfer that still needs a factor goes to the sign-in route for it (#/factor-one, #/factor-two, #/reset-password or #/protect-check), like clerk.ts _handleRedirectCallback, and keeps redirect_url. fix(mosaic): send a social sign-up transfer to the sign-in step it still needs, covered by "hands a transfer that still needs a second factor to the sign-in factor-two route, keeping redirect_url".
  • A transfer after a solved Protect check signs in instead of stalling on the Protect screen. fix(mosaic): transfer a social sign-up after its Protect check is solved, covered by "signs in instead after the Protect check when the Google account already belongs to a user".
  • The OAuth completion runs inside the model's completeReturn. refactor(mosaic): settle the sign-up OAuth return inside completeReturn, a refactor. test(mosaic): cover social sign-up's existing session, Protect after the return, and the sso body adds "switches to the session already signed in to the Google account and lands on $landing", "runs the Protect check the sign-up still has after the return, then continues" and "sends the accepted legal terms and the unsafe metadata with the Google sign-up".
  • REDIRECT_HOLD_MS moved from user-profile to src/utils/redirect.ts, shared by both features. refactor(mosaic): share the redirect hold between sign-up and user profile.
  • The flow doc describes the return as built and says the marker moves to useReturnUrl() (feat(mosaic): Add useReturnUrl and sync query mode links into other modes #10860) when that hook lands. docs(mosaic): describe the sign-up OAuth return as built.
  • The fake FAPI can raise the Protect check on the return from Google, as clerk_go does. test(mosaic): run a Protect check raised on the return from Google, covered by "runs the Protect check raised on the return from Google, then completes the sign-up".
  • Continue hides the providers only when legal consent is the one thing the sign-up still needs, as legacy does. Before, a sign-up missing both legal consent and a provider hid that provider and could not finish. The rule lives in the model's continueProviders alone. fix(mosaic): hide Continue's providers only when legal consent is all a sign-up needs, covered by "offers the provider the sign-up still needs alongside legal consent" and "offers no provider when legal consent is all the sign-up needs".

1. The model lists the providers and starts the redirect. The providers come from userSettings.authenticatableSocialStrategies, custom ones included, sorted the way legacy sorts them. Start shows them next to the WhatsApp buttons. Continue shows them too, until the sign-up has a verified external account. When FAPI lists an oauth_* provider in missing_fields, continue shows only the missing providers instead of Start over, since another provider can't satisfy the requirement. When more than one provider is required, one sign-in can't satisfy them all, so sign-up still shows Start over. On an instance with no form fields, start shows only the providers, and legal consent is asked on continue. The user links the rest from their profile. sso() sends the consent checkbox and unsafeMetadata. signUp.sso() updates any sign-up already on the client, so start resets a leftover sign-up first, unless it is the invitation's. A blocked request from start shows the blocked notice.

await run(() =>
  target.sso({
    strategy,
    redirectCallbackUrl: ssoCallbackUrl(), // current URL + __clerk_mosaic_sign_up=sso-callback
    redirectUrl: afterSignUpUrl, // honors redirect_url
    unsafeMetadata,
    legalAccepted: legalAccepted || undefined,
  }),
);

2. The return is marked in the URL. Mosaic routing is in memory, so the provider's redirect would land back on start with no memory of the flow. Until URL routing lands in #10860, the callback URL carries a marker, the way withUserProfileModalReturn marks a profile return. The marker moves to that PR's useReturnUrl() when it lands. When sign-up opens with the marker, on any route, the controller shows the loading screen from the first paint and runs completeReturn once as its return action. The ticket waits until the return is done.

const isReturning = actions.pendingKey === 'return' || (flow.isReturning && actions.lastKey === undefined);

3. completeReturn follows clerk.handleRedirectCallback's sign-up branches on the Future API.

After the provider Sign-up
A Protect check the protect screen, before anything else. A transfer after it still signs in
Something is still missing next(step): continue or verify
The account already exists signIn.create({ transfer: true }), then finishes in place, or goes to the sign-in route for the factor it still needs
The user is already signed in with it activates that session; a pending task goes to its task URL, as for a transfer
The provider returned an error forgets the ticket, resets the sign-up and shows the error on start: FAPI's message for the codes legacy shows, the generic error otherwise
FAPI blocked the sign-up the blocked notice

A transfer and a switch to an existing session both keep redirect_url.

The model picks the error copy on purpose. The error is read off signUp.verifications.externalAccount after the redirect, not thrown by a Clerk call, so it is a failure the model detects (models.md). It shows FAPI's message for the 17 codes legacy shows (SignUpStart.tsx handleOauthError) and the generic error for every other code, so server detail stays hidden as it does in legacy. Moving that choice to the error owner would need a new shared option with one caller.

Popup mode (oauthFlow) and enterprise SSO come in stacked follow-ups. The fake FAPI starts OAuth sign-ups, plays the provider's response, raises a Protect check on the return when seeded to, and transfers to sign-in, so the feature tests cover each return.

Changes outside sign-up

  • REDIRECT_HOLD_MS lives in src/utils/redirect.ts, listed in AGENTS.md's reuse list. The user profile's connected and enterprise accounts sections import it from there.

Known gaps

  • An OAuth transport (__internal_oauthTransport) is not supported. SignUpFuture.sso() still navigates the window, so clerk-js has to honor the transport first.
  • The marker is gone once the return starts, so a reload mid-return lands on start.
  • OAuth is a full-page redirect only. Popup OAuth is not built.
  • In multi-session mode, a Google sign-up that ends with a pending setup-mfa task shows an empty form. This was seen against the fake FAPI only.
  • A transfer that lands on needs_first_factor or needs_new_password, and a sign-in Protect check after a transfer, are not covered by tests. The fake FAPI has no sign-in Protect or first-factor transfer.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clerk-js-sandbox Ready Ready Preview Nov 26, 2026 8:08am UTC
mosaic-docs Ready Ready Preview Nov 26, 2026 8:08am UTC
swingset Ready Ready Preview Nov 26, 2026 8:08am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@changeset-bot

changeset-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 372e71e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@10945

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@10945

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@10945

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@10945

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@10945

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@10945

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@10945

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@10945

@clerk/expo-biometrics

npm i https://pkg.pr.new/@clerk/expo-biometrics@10945

@clerk/expo-google-signin

npm i https://pkg.pr.new/@clerk/expo-google-signin@10945

@clerk/expo-native-components

npm i https://pkg.pr.new/@clerk/expo-native-components@10945

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@10945

@clerk/express

npm i https://pkg.pr.new/@clerk/express@10945

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@10945

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@10945

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@10945

@clerk/mosaic

npm i https://pkg.pr.new/@clerk/mosaic@10945

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@10945

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@10945

@clerk/react

npm i https://pkg.pr.new/@clerk/react@10945

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@10945

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@10945

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@10945

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@10945

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@10945

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@10945

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@10945

commit: 372e71e

…ith social sign-up

The restack onto the invitation fixes put `useSignUpModel` at a cognitive complexity of 18. Choosing which legal consent start and continue show moves above the returned model, where each choice counts once instead of at the model's nesting depth.
…ith an error

The error path reset the sign-up but left the ticket in the URL, so the invitation effect redeemed it again and cleared the provider's error. It now removes the ticket first, as the flow's own reset does. A successful return keeps the ticket, so the invitee stays on the invitation's sign-up.
…-up opens

The return only ran on start, so a return that opened on continue showed the loading screen forever. It now runs once on any route, and the guard then moves the screen to the step's route.
…ts pending action

The controller kept `isReturning` in its own state beside `usePendingAction`, a second busy flag. It now reads the return marker until the return action has run, then the action's pending key, so the loading screen still shows from the first paint.
`sso` built the after-sign-up URL without the query, so a `redirect_url` on the page was dropped once the provider finished. It now passes the same after-sign-up URL the rest of sign-up uses.
…ill needs

A transfer that did not complete went to the sign-in root. It now goes to `factor-one`, `factor-two`, `reset-password` or `protect-check` by the sign-in's status, as `clerk.ts` `_handleRedirectCallback` does, on the sign-in URL that keeps `redirect_url`.
…hook

The return completion (Protect, transfer, existing session, provider error, next step) becomes a module function, so the return and the Protect check after it share one path.
…the return, and the sso body

The fake FAPI can now return an OAuth sign-up for an account already signed in on the client, with FAPI's `identifier_already_signed_in` error and its session id.
…ofile

Sign-up imported `REDIRECT_HOLD_MS` from `user-profile.utils`. It moves to `src/utils/redirect.ts`, beside the other cross-feature values, and AGENTS.md lists it.
The flow doc said redirect URLs are never hand-built and that sign-up keeps the screen on every transfer, while the OAuth return builds a marked callback URL and transfers an existing account itself. It now says the marker is temporary until the router's `useReturnUrl()` lands, and describes the return as built: any route, the ticket kept on success and removed on error, the sign-in route a transfer needs, `redirect_url`, and the OAuth transport.
clerk_go 8bb8f66dde runs the sign-up Protect check on the OAuth callback
for a new account (api/fapi/v1/oauth/oauth.go:2767, FlowOpOAuthCallback in
api/shared/sign_up/flow_stage.go:93-96 surfaces it on the next read). An
account that already exists returns before that check (oauth.go:2747-2752),
so a check raised on the return never leads to a transfer.

The fake FAPI can now raise the check on the return
(protectCheckOn: 'oauth_callback'), keeping a pending, unexpired check the
way runProtectCheck does. The new test lands on the Protect screen after
Google and completes the sign-up once the user solves it.
Inlines the one-caller completeOAuth and its actions object, drops a guard the
early return already covers, and stops asserting the internal return marker.
…n-in

The sign-up model built the after sign-in URL without the query, so a Google account that already had a user, or was already signed in on this client, landed on the sign-in fallback instead of the redirect_url. Both paths now pass the query to buildAfterSignInUrl, as sign-up does for the after sign-up URL and as legacy does (ui/src/contexts/components/SignUp.ts).
…s blocked

Fails today. FAPI stores `action_blocked` with its details on the external account verification when Protect blocks the callback, and sign-up shows it as an inline error on the start form. The fake FAPI's OAuth error takes the `meta` FAPI stores with it.
… blocked

`completeReturn` resolves with the blocked result when the external account's error is `action_blocked` with its details, as legacy's `SignUpStart` shows `ActionBlockedCard` for it. The controller keeps the result for the mount, like a blocked create. An `action_blocked` error without details still shows inline on the start form.
…is blocked

Fails today. The blocked notice now comes from the result a request resolves with, and `sso` still rejects with the error, so the start form shows it inline.
…s blocked

`sso` resolves with the blocked result from the start form when FAPI answers `action_blocked`, and the details controller hands it to the flow, which keeps it for the mount. From the continue form it still rejects, so the error shows inline, as a blocked update does and as legacy's `SignUpContinue` shows it.
The social sign-up tests move out of the shared sign-up feature test, with the three provider tests that sat among the continue screen tests, and are grouped by what the user is doing in place of one "SignUp social sign-up" block.

Starting with Google, signing in instead, and switching to a signed-in session each had one test for the fallback URL and one for the redirect_url in the query. Each pair is now one table over the two landings.

This branch was successfully deployed

2 active deployments
Preview – swingset — 372e71eb Deployed Nov 26, 2026 by vercel[bot]
Preview – clerk-js-sandbox — 372e71eb Deployed Nov 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant