Skip to content

refactor(auth): adopt @comfyorg/account in cloud sign-in - #17120

Closed
MaanilVerma wants to merge 120 commits into
maanil/account-package-corefrom
maanil/workshop-account-package
Closed

MaanilVerma wants to merge 120 commits into
maanil/account-package-corefrom
maanil/workshop-account-package

Conversation

@MaanilVerma

@MaanilVerma MaanilVerma commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Stack (10 PRs): #17127 → #17120 → #16980 → #16983 → #16984 → #16986 → #16987, with #17125 → #17126 → #17163 branching off #17120 for the cloud app. This is PR 2: cloud sign-in adopts the package. Billing commands and the Vue layer from the account TDD are out of scope for the whole stack.

Summary

The cloud app repoints every importer to @comfyorg/account (#17127) and deletes the inline originals, then binds the package's Firebase entry to the vuefire Auth it already holds so sign-in, sign-up, popup, reset, and sign-out run through the same code the Workshop site does.

Changes

  • authStore.ts runs its providers, popup sign-in, email sign-in and sign-up, password reset, and sign-out through createFirebaseIdentity({ auth }) on the existing vuefire instance, no second Firebase app. Providers, scopes, and the select_account prompt are unchanged; the auth listener and the ADR-0028 identity adapter are untouched.
  • authStore.ts provisions through @comfyorg/account/provisioning, and createCustomer keeps its original payload shape and byte-identical request.
  • useAuthActions.ts resolves error copy through authErrorMessage over the app's own vue-i18n table instead of hand-branching per Firebase code.
  • Turnstile trio (useTurnstile, turnstileScript, sign-in dialog widget) delegates to the package, src/composables/auth originals deleted.
  • signInSchema.ts becomes a thin i18n shim over the package's shared rules, its test moves with it.
  • PasswordFields.vue renders the package's PasswordRules.vue, passing in the exact classes the cloud DOM already used, markup is byte-identical.
  • TurnstileWidget.vue swaps its template for the package's shared widget.
  • churnkeyClient, useTypeformEmbed, SyftTelemetryProvider repoint to @comfyorg/shared-frontend-utils/loadExternalScript.

Breaking: None.

Behaviour changes to main, both deliberate, both in the name of not letting the sign-in surfaces enumerate accounts (the account TDD's email-policy ask):

  • A password reset for an email with no account resolves as sent (success toast, the forgot-password confirmation, the redirect to login), the same answer Firebase gives once Email Enumeration Protection is on. Pinned in authStore.test.ts ("password reset"). The reset error still surfaces for every other failure.
  • en/main.json collapses auth/user-not-found and auth/wrong-password into the invalid-credential line. Only en is edited by hand; the translation job fans the change out to the other fifteen locales from that source, and src/locales/authCopy.package.test.ts pins en by value and ja/zh by key set only, so regenerated translations never fail it.
  • Sign-up still returns auth/email-already-in-use; the neutral sign-up flow needs the email-verification step, which stays deferred with the rest of the email policy.

Review Focus

  • The vuefire Auth bind (createFirebaseIdentity({ auth })) is the one place this diff changes how identity reaches the session: no second app, no timeouts on the network-shaped actions, same providers and prompts.
  • TurnstileWidget.vue's template swap and the PasswordFields.vue markup pin are the two spots with real UI risk. The markup pin test is what proves the DOM held.

Testing

Automated: authStore.test.ts (111) and useAuthActions.test.ts pass with providers, popup, and email flows unchanged. Turnstile suites pass with only relocated cases trimmed. Package suite 247/247. Full selection (packages/account, authStore.test.ts, cloud auth composables, sign-in dialog, cloud onboarding, signInSchema) 48 files / 725 tests. Typecheck and lint clean.

Manual checklist (Turnstile is a live Cloudflare widget, can't be faked in a suite):

  • Open the sign-up dialog with Turnstile enabled, confirm the challenge renders, solves, and unblocks submit
  • Trigger an expired or failed challenge, confirm the error text renders
  • Sign in with Google and GitHub, confirm the popup, scopes, and post-auth redirect are unchanged

benjcooley and others added 30 commits September 3, 2026 16:42
Adds a Run control to the model page. It posts the values already in the
form to Comfy Router and renders what comes back.

The run route is synchronous — one POST carries the input and the reply
carries the finished result — so there is no job to poll and no state to
keep between requests.

Credentials are a Comfy API key the visitor pastes, kept in this browser
only. comfy.org has no signed-in session yet: the origin is not on the
Firebase authorized-domains list, so a sign-in popup there fails before it
starts. When that lands, a session token becomes a second source behind
the same call and the key stays as the fallback developers want anyway.

This calls fetch directly rather than using @comfyorg/sdk. The published
SDK still imports node:crypto and node:fs at module scope and cannot be
bundled for a browser; the fix is open but unreleased, and the whole
contract here is one POST, so waiting on it would buy nothing.

Router returns the partner's own JSON unchanged, so there is no result
field we are entitled to expect. The panel walks the document for media
URLs, decides how to render them from the model's modality rather than
from the URL, and always offers the full response underneath.

Removes the permanently disabled "Run model — sign-in coming next" button
from the form. A dead control beside a working one is worse than none.

Verified against production Router from a real browser: the POST reaches
api.comfy.org, CORS passes, and a bad key renders as "That API key was
not accepted." with Router's own message and the request id beneath it.
… sign-in

Reworks the model page to match the platform playground's layout, and adds
the sign-in wall the run path was missing.

Layout. Playground and API are tabs rather than columns, so the result sits
beside the form at 2:3 instead of below the fold while the code snippet took
half the page. Cards size to their content.

Running. The output panel leads with a single large action. Signed out it
reads "Sign up / Login to Render" and opens a dialog; signing in starts the
run immediately rather than making you press a second time. While a run is
in flight the result area holds an aspect-correct placeholder with a slow
sweep, the expected duration for that output type, and elapsed time — there
is no progress signal to report, so it sets an expectation instead of
animating a number we would be inventing. Dropped under reduced motion.

Every model now opens with a prompt already in the box, chosen per output
type: an audio model reads its prompt aloud, so it gets a sentence rather
than a scene description. It never overrides a default the model specifies.

The credential is temporary scaffolding and lives only inside the sign-in
dialog, shared through a module-scoped ref rather than component props, so
that deleting one component is the whole removal once comfy.org can start a
real session.

Also adds a local-only path that runs models through the vendored partner
client instead of Router. It is off unless PUBLIC_WORKSHOP_PARTNER_PROXY=1,
which only a gitignored .env does, so every build and test still exercises
the committed Router path. See the note on workshop-run-proxy.ts for why it
is needed: our form values are a normalized shape that neither Router nor
the proxy accepts directly.
Takes the layout from Mariana's prototype (PR #16556) rather than the
platform playground I had copied, which turned out to be a different and
older arrangement.

Twelve-column grid at 5:7 instead of my 2:3, INPUT and OUTPUT as titled
cards rather than bare sections, field labels uppercase with the
description beneath, and the run control at the foot of the input card
where the prototype puts it — not floating above the output.

Three things in the prototype are not reproduced here, all for want of
data rather than disagreement:

- The output card shows a real example result before you run anything,
  captioned "This is the example result. Run to generate your own." That
  needs per-model example media, which is the content pack. Ours holds
  the space with a placeholder until it lands.
- An EXAMPLES tab beside PLAYGROUND and API, same reason.
- A hero band with per-run credit cost, run count, and model-version
  chips. The version chips are how the prototype sidesteps the
  task-addressed vs version-addressed catalog split, and are worth
  revisiting when that is settled.

The run button also keeps the wording asked for here rather than the
prototype's SIGN IN TO RUN.
It held a dashed box reading "Your result will appear here", which is a
placeholder standing in for the prototype's example output. Saying nothing
is better than announcing an absence: the card is now just its header until
a run produces something.
… space

The prototype opens with a hero carrying a still from the model, and its
output card holds the shape of a result before one exists. Both are space
the page should occupy from the first paint.

We have no per-model art yet, so neither is filled: the hero is the band
and its gradient with the title block over it, and the output card holds an
empty 16:9. When the content pack lands, the image drops in behind the hero
and into the output card without anything else moving.

Reserving rather than filling is the point. A placeholder that announces
what is missing is worse than a quiet gap, but a gap that appears only
after you press Run shoves the page around at the moment you are watching
it most closely.
Move the portable, tested auth logic out of the app so the website can
consume it without reimplementing: sign-in/sign-up zod schemas (now a
factory taking the host's translator), the Turnstile widget machine and
its gating state (sitekey/theme/copy/loader become props), the script
loader (to shared-frontend-utils), Firebase auth error classification,
and new provisioning sequences encoding the sign-up rollback and
social-always-provisions invariants. The app keeps thin shims at every
old import path, so its suites run unchanged.
Completes the extraction commit: the timed-out pre-commit run left the
shim edits and workspace wiring (package.json, knip, lockfile) unstaged,
so the moved modules landed without their app-side consumers.
…gnup error

Red: onRollbackFailure is invoked unguarded in signUpWithProvisioning, so a
throwing telemetry sink displaces the original provisioning error before the
rethrow. QA finding S1-5. Fix follows.
…ards

Green for the throwing-rollback-sink defect: the onRollbackFailure
invocation is wrapped so a throwing telemetry sink can no longer displace
the original provisioning error. Plus the QA test-adequacy gaps on this
slice: classifyAuthError now covers an auth/ code with a missing or
non-string message landing in unknown; the Turnstile 'clears unavailable'
test actually drives a timed-out widget recovering on a late token; and
the createAuthSchemas doc drops the migration-history clause.
…ype shim

The new @comfyorg/auth-core workspace package has no license field, so the
production license check rejected it as UNLICENSED; add it to the same
excludePackages list every other first-party @comfyorg package already uses.
Also add partner-client.d.ts here so the gitignored LOCAL-ONLY vendor bundle
imported by workshop-run-proxy.ts type-resolves on this branch, matching the
copy the later slices carry.
…n/workshop-run

# Conflicts:
#	apps/website/src/components/workshop/WorkshopForm.test.ts
…rkshop-shared-auth-core

# Conflicts:
#	apps/website/src/components/workshop/WorkshopForm.vue
#	apps/website/src/components/workshop/WorkshopPlayground.vue
#	apps/website/src/components/workshop/WorkshopRunPanel.test.ts
#	apps/website/src/components/workshop/WorkshopRunPanel.vue
#	apps/website/src/config/workshop-run-target.ts
#	apps/website/src/i18n/translations.ts
@MaanilVerma
MaanilVerma force-pushed the maanil/workshop-account-package branch from d65498e to 6aae20c Compare September 10, 2026 06:41
MaanilVerma and others added 6 commits September 10, 2026 13:56
The root app scanned the account package by reaching into its source with a repo-relative path (@source '../../../packages/account/src'), which bypasses the package boundary and breaks if the package moves or is packaged. Ship packages/account/src/styles.css (a @source './' scoped to the package's own location), export it as ./styles.css, and have the consumer @import that stable entry instead.
Per the Account Layer TDD the package ships unstyled components and each host owns presentation, so the package must not carry CSS. The account components use only common structural utilities (flex, gap-2, size-5, shrink-0) that every host already generates from its own source, so scanning the package added nothing. Remove the package-owned styles.css entry and the root app's @source into the package src rather than formalizing a scan the unstyled-package design does not need.

@dante01yoon dante01yoon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the current incremental adoption diff and follow-up changes. Turnstile forwarding, translated error handling, telemetry fallback, and generated-translation coverage are resolved; I found no remaining blocking defect at this head.

@dante01yoon dante01yoon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A stricter consumer pass found a credential-ownership race in customer provisioning.

Comment thread src/stores/authStore.ts Outdated
const result = await executeAuthAction(() =>
signUpWithProvisioning({
createUser: () => identity.createUserWithEmail(email, password),
provisionCustomer: () =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: signUpWithProvisioning passes the credential that actually completed signup into this callback, but the callback ignores it. createCustomer() later gets headers from whichever store/Firebase identity is current at that moment. If A completes signup and auth switches to B before provisioning, B can be provisioned while this flow returns and records A; for email signup, A may then be rolled back as orphaned even though the POST used B. The social callbacks have the same issue. Could provisioning accept the completed credential and derive its Firebase header directly from that user, as the website consumer already does?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — provisioning now threads the completed UserCredential into createCustomer and derives the Firebase header (and the recorded identity) from that user rather than whatever identity is current; both the email and social paths. A concurrent auth switch can no longer provision or roll back the wrong account. 32cc7cf686. Red-green test: "provisions with the completed credential, not whatever identity became current".

@dante01yoon dante01yoon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the credential-threading fix. Email and social provisioning now use the exact completed UserCredential, and rollback remains scoped to that credential; the prior consumer race is resolved. Holding approval for the unresolved #17127 customerRecovery contract blocker and pending CI.

@dante01yoon dante01yoon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the exact current head. Provisioning is pinned to the completed UserCredential for email and social flows, rollback ownership is correct, and all checks are green. Approving this incremental PR; #17127 remains separately blocked by its customerRecovery contract.

@dante01yoon dante01yoon removed their assignment Sep 10, 2026
benjcooley added a commit that referenced this pull request Sep 10, 2026
## Summary
One shared sign-in system for comfy.org and cloud.comfy.org: a new
`@comfyorg/account` package holds the session core, and both apps adopt
it instead of each hand-rolling their own auth. This PR combines the ten
PRs that built it, already reviewed and individually CI-green, into one
branch for final review.

## Combined from
| # | Title | Highlights |
|---|---|---|
| [#17127](#17127) |
feat(account): add `@comfyorg/account` with session core, credits
client, and Firebase identity | The package itself: valid-on-read
session mint/refresh with a 5-minute floor, uid-keyed cache,
single-flight dedupe, an identity-epoch guard so a stale mint can't
publish after sign-out. Shared credits client, Firebase identity entry,
password-rule and social-button components, shared error copy. No
consumer yet. |
| [#17120](#17120) |
refactor(auth): adopt `@comfyorg/account` in cloud sign-in | Cloud
repoints its sign-in, Turnstile, and password-rule code to the package
and deletes the inline originals. Two deliberate account-enumeration
closures: an unknown-email password reset now resolves as sent, and
`user-not-found`/`wrong-password` collapse into one invalid-credential
message. |
| [#16980](#16980) |
feat(auth): sign in to Comfy from comfy.org with Google or GitHub |
Google/GitHub sign-in on comfy.org behind the `workshop-auth` flag,
matching the cloud app's actual behavior (error copy, timeout handling,
funnel events), not just its look. |
| [#16983](#16983) |
feat(workshop): establish a signed-in workspace session | A minted,
auto-refreshed workspace session for signed-in visitors. Fixes a
redirect race where a fast page could reach `signedIn` before its own
redirect ran, and closes an open-redirect hole in the post-sign-in
return URL. |
| [#16984](#16984) |
feat(website): show the signed-in account and credits in the site header
| Account and credit balance in the header, desktop and mobile, with a
real four-state UI (sign-in link, error retry, signing-in, signed-in)
instead of the retry and loading states looking identical. |
| [#16986](#16986) |
feat(workshop): keep the form across sign-in and purchase round trips |
A Workshop model form's values survive a sign-in or purchase round trip
instead of being lost. Stashed values are validated against the current
field's kind before restoring, so a changed form degrades to defaults
rather than injecting a mismatch. |
| [#16987](#16987) |
feat(auth): sign in or create a Comfy account with email and password |
Email/password sign-in, sign-up, and forgot-password on comfy.org.
Sign-in and sign-up switch panels without a page reload. Firebase loads
lazily inside the submit handler so a flag-off visitor never ships the
chunk. |
| [#17125](#17125) |
feat(account): cloud-host capabilities for the session client | Grows
the package with what cloud's unified auth needs: workspace-targeted
minting, an opt-in refresh scheduler with backoff, `invalidate()` for
scope changes, and credential preservation across a transient mint
failure. No `apps/website` changes. |
| [#17126](#17126) |
refactor(cloud): unified auth path delegates to `@comfyorg/account` |
Cloud's flag-gated (`unified_cloud_auth`) mint and refresh internals
become wrappers over the shared client: one lifecycle implementation for
both apps. Identity reaches the client through a Firebase-entry port
rather than a hand-rolled push from Pinia. Carries
ADR-AUTH-IDENTITY-0028. |
| [#17163](#17163) |
feat(account): cross-tab refresh coordination for the unified session |
With multiple tabs open, one tab refreshes the session token and the
others adopt the result over BroadcastChannel, instead of every tab
minting its own copy. A tab that loses its leader falls back to a
self-mint after a short random hold. |

## Breaking
None across the stack. `unified_cloud_auth` and `workshop-auth` both
default off, so unflagged builds see no behavior change. Existing
session storage keys, telemetry events, and deeplinks are unchanged.

## Review Focus
Two merge conflicts came up assembling the ten branches into one, both
resolved by hand:
- `useWorkspaceAuth.test.ts`: main had picked up an unrelated
global-Pinia test migration after this stack's last sync, colliding with
#17126's newer event-driven identity-port mock. Took #17126's version,
verified as a strict superset of every test on the stack's other
branches.
- `packages/account/package.json`: two branches added different
`exports` entries (`./web`, `./SocialAuthButtons.vue`) for files that
both exist in the merged tree. Kept both.

The identity-port wiring in ADR-AUTH-IDENTITY-0028 is worth a close
look: `authStore` no longer pushes identity into the session client, and
every mint waits for the port to have delivered the app's current user
instead.

Out of scope: cross-domain session (a comfy.org sign-in carrying over to
cloud.comfy.org and platform.comfy.org) needs backend changes not yet
landed (cloud #8601, #8602).

## Testing
Each of the ten PRs shipped its own automated coverage and manual
checklist; combined here rather than repeated per-file.

Automated, per PR: package suite 247/247 (#17127, #17125), cloud
adoption suites (`authStore.test.ts`, `useAuthActions.test.ts`,
Turnstile) unchanged (#17120), website suite 212/1504 plus e2e (#16980,
#16983, #16984, #16986, #16987), unified-lifecycle suite 94 tests
through the fake identity port with zero edits to four dependent suites
(#17126), scheduler and cross-tab channel suites plus a live two-tab
Playwright spec (#17163). Typecheck and lint clean on every branch and
on the combined result.

**Combined manual QA checklist** (carried over from the individual PRs,
needs a live Firebase project and backend):
- [ ] Sign in with Google and GitHub from comfy.org, confirm the popup,
scopes, and redirect match cloud
- [ ] Open the sign-up dialog with Turnstile enabled, confirm the
challenge renders and unblocks submit; trigger an expired/failed
challenge and confirm the error renders
- [ ] Create an account with email/password on comfy.org, then sign in
with it
- [ ] Request a password reset for a registered email, confirm you get
the mail; request one for an unregistered email, confirm the identical
"sent" state
- [ ] Enter a wrong password, confirm the error doesn't reveal whether
the email is registered
- [ ] Click between sign-in and sign-up a few times, confirm no reload
and Back/Forward track the mode
- [ ] Sign in, confirm the header shows the account with a minted
session and credit balance; refocus the tab and confirm a silent refresh
- [ ] Fill in a Workshop form, sign in, confirm your values are back on
return; include a media field and confirm it isn't restored with a stale
filename
- [ ] Visit a `returnTo` with an embedded control character pointing
off-site, confirm you land on `/workshop/`, not the external site
- [ ] Sign in, then reload `/login/`, confirm you land on the home page
without the form flashing
- [ ] Flag-on cloud backend: login, workspace switch, shortened-TTL
expiry, 401 replay, logout
- [ ] `DISTRIBUTION=cloud` build, sign in, open two tabs, confirm one
tab holds the refresh lock via `navigator.locks.query()`; close the
leader tab and confirm the lease moves to the survivor

---------

Co-authored-by: Maanil Verma <maanil@comfy.org>
Co-authored-by: benjcooley <benjcooley@gmail.com>
@MaanilVerma
MaanilVerma marked this pull request as draft September 11, 2026 12:16
@MaanilVerma

Copy link
Copy Markdown
Collaborator Author

The combined unified-auth PR (#17283) has been merged to main. Keeping this open for tracking the remaining e2e work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:xhigh PR risk grade (advisory shadow check; grader-owned)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants