Commit 848cd39
feat(workspace): enable local credit workspace switching FE-1584 (Comfy-Org#15164)
## Why
Local/Desktop users cannot select the workspace that owns their
subscription or credits. The existing workspace and billing clients also
resolve through `api.apiURL()`, which points at the local ComfyUI server
off Cloud, so simply exposing the Cloud switcher leaves workspace
hydration dormant and returns 404s.
## Root cause
The Cloud-only UI guard hid the switcher, but the deeper boundary was
also Cloud-only:
- workspace token exchange, workspace listing, and `/billing/*` used
same-origin URLs
- generic auth helpers mixed Firebase user identity with
workspace-scoped identity
- Cloud workspace switching reloads the app and changes
workflow-persistence namespaces, which is incorrect for Local/Desktop
where workspaces are credit wallets only
## Change
- Expose the existing workspace switcher in Local/Desktop after Firebase
auth hydrates; keep workspace creation Cloud-only.
- Route workspace auth, listing, and billing requests to the build's
Firebase-paired Cloud gateway (`cloud.comfy.org` in production,
`testcloud.comfy.org` in non-production) while Cloud remains
same-origin.
- Separate Firebase-authenticated `/customers/*` calls from
workspace-authenticated billing and partner-node execution.
- Switch the active local credit context without reloading or moving
local workflow persistence; persist the selected wallet per device.
- Keep Add credits permission-aware and return completed/pending top-ups
to Settings → Credits on Local/Desktop.
### Implementation scope and rationale
| Area | Change | Why it is required |
| --- | --- | --- |
| Workspace API routing | Resolve workspace and billing requests through
the Firebase-paired Cloud gateway outside the Cloud distribution. |
Local `/api` targets the local ComfyUI server, while workspace and
billing state is owned by Cloud ingest. |
| Authentication boundary | Separate Firebase user authentication from
workspace-scoped authentication, including partner-node queue execution.
| A Firebase token identifies the user; the workspace token
deterministically identifies the wallet that owns credits and receives
usage charges. |
| Workspace bootstrap | Share and await the in-flight Local workspace
initialization, and fail closed when no active workspace can be
established. | Prompt submission during bootstrap must not run without
credentials or silently fall back to the personal workspace. |
| Local switch lifecycle | Switch the active credit workspace without
reloading the document. | Cloud reload semantics are unnecessary for
Local and would interrupt the current local workflow. |
| Workflow persistence | Keep Local workflow storage in the personal
namespace when the credit workspace changes. | Local workspace selection
changes the billing wallet only; it must not move, clear, or split
locally stored workflows. |
| Billing routing | Use workspace billing after Local workspace
hydration. | Balances, plans, billing events, and top-ups must follow
the selected credit workspace rather than the personal account. |
| Billing permissions | Keep Credits visible while hiding Add credits
for members who cannot top up. | Backend top-up operations are
owner-only, so the UI must not offer an action the selected workspace
role cannot perform. |
| Top-up completion | Return completed or pending Local top-ups to
Settings → Credits. | Local does not expose the Cloud
workspace-management destination used by the existing Cloud flow. |
| Cloud customer endpoints | Explicitly retain Firebase authentication
for user-scoped customer and subscription calls. | Changing generic auth
precedence must not send a workspace token to endpoints whose contract
is user-scoped. |
| Feature-flag isolation | Disable `unified_cloud_auth` outside the
Cloud distribution. | Unified Cloud JWT minting is not available in
Local/Desktop; accepting that flag there would break workspace discovery
and execution authentication. |
| Regression coverage | Add focused unit tests and a Local Playwright
workspace-switching flow. | The tests protect workspace attribution,
Cloud-gateway routing, no-reload switching, workflow retention,
permissions, and bootstrap race handling. |
Backend dependency:
[cloud#6635](Comfy-Org/cloud#6635) is required
and merged. Its Local/Desktop CORS scope covers `POST /api/auth/token`,
`GET /api/workspaces`, and `GET`/`POST /api/billing/*`; Local keeps
workspace creation hidden. The backend PR is merged into `main`, and its
production manifest contains the loopback origins. A live preflight
currently passes on `testcloud.comfy.org`, while `cloud.comfy.org` still
omits `Access-Control-Allow-Origin` for loopback origins. No additional
backend code change is currently identified; the remaining release check
is to confirm the merged configuration has rolled out to the production
runtime and repeat the preflight.
[Comfy-Org#15151](Comfy-Org#15151)
independently fixes the existing Settings → Credits activity spinner and
billing-portal rail.
## Plan / QA
1. Review the auth and persistence boundaries in this PR.
2. Land Comfy-Org#15151 so activity and Invoice History follow the selected
billing rail.
3. Confirm the merged cloud#6635 configuration has rolled out to the
production runtime and repeat the live preflight.
4. Verify on a Desktop build against the deployed gateway:
switch/relaunch, popover and Settings balances, top-up attribution,
partner-node debit and allowlist, member permissions, and zero-credit
local runs.
Regression audit added a focused Local Playwright flow. It caught and
fixed two release blockers: Local rendered the legacy profile popover
even after workspace hydration, and `unified_cloud_auth=true`
incorrectly selected an unavailable Cloud JWT outside the Cloud
distribution. The E2E verifies workspace/role rendering, workspace token
exchange, Cloud-gateway billing routing, and that switching neither
reloads the document nor loses the open workflow tab.
A second auth/accounting audit found two queue-time races: a prompt
could be submitted without a workspace token while Local workspace
bootstrap was in flight, or fall back to the personal Firebase identity
after bootstrap failed. Queue authentication now shares and awaits the
in-flight workspace initialization and fails closed if no active
workspace can be established. Identity-generation guards prevent a
previous user's initialization from overwriting the next user's state.
Design of record: [MVP
before/after](https://www.figma.com/design/CkFTD4c20PyRGpNVAJgpfV/Team-Plan---Workspaces?node-id=5874-73181)
· [popover and
switcher](https://www.figma.com/design/CkFTD4c20PyRGpNVAJgpfV/Team-Plan---Workspaces?node-id=5874-72771)
The implementation references those prototype states: the profile
popover gains the workspace row, the selector opens to the left, and the
selected workspace is highlighted with a check while roles remain
visible. Local-specific adaptations are the compact single-line trigger
and the retained Credits entry, because this scope adds wallet switching
without exposing Cloud workspace management.
| AS IS — Local profile menu | TO BE — Local workspace selector |
| --- | --- |
| 
| 
|
Captured from the actual Local frontend at 1920×1200 with deterministic
auth/workspace/billing API fixtures; no Figma image is substituted for
the implementation capture.
## Validation
- Focused Local workspace Playwright E2E: 1/1 passed on Chromium before
the final auth-race patch; final local rerun was blocked during fixture
setup because the 8188 ComfyUI test backend was unavailable, before any
product assertion ran
- Final focused workspace/auth/queue unit suites: 316/316 passed when
run in their stable focused groups
- Earlier affected unit/component suites: 650/650 passed before rebase;
594/594 passed after rebase
- `pnpm typecheck`
- targeted ESLint and oxfmt checks
- `pnpm knip` reports only existing repository-wide unused
dependency/export findings
- Real-app screenshot Playwright run: 2/2 passed (AS IS without a
workspace roster; TO BE with the selector open)
- Live CORS preflight: staging passes; production runtime rollout/sync
verification remains the release blocker
Linear:
[FE-1584](https://linear.app/comfyorg/issue/FE-1584/add-workspace-switcher-to-localdesktop-credits-only-no-settings)
---------
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: comfydesigner <alextov@comfy.org>1 parent bfb6cd0 commit 848cd39
49 files changed
Lines changed: 1206 additions & 135 deletions
File tree
- browser_tests
- fixtures
- tests
- workspace
- src
- components/topbar
- composables
- billing
- config
- locales/en
- platform
- cloud/subscription
- components
- composables
- utils
- workflow/persistence
- base
- composables
- workspace
- api
- auth
- components
- stores
- scripts
- services
- stores
- __tests__
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
| |||
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
54 | 68 | | |
55 | 69 | | |
56 | 70 | | |
| |||
Lines changed: 95 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
220 | 241 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| |||
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
| 81 | + | |
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
| |||
121 | 124 | | |
122 | 125 | | |
123 | 126 | | |
124 | | - | |
| 127 | + | |
125 | 128 | | |
126 | 129 | | |
127 | 130 | | |
| |||
132 | 135 | | |
133 | 136 | | |
134 | 137 | | |
135 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
136 | 147 | | |
137 | 148 | | |
138 | 149 | | |
| |||
382 | 393 | | |
383 | 394 | | |
384 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
385 | 493 | | |
0 commit comments