Skip to content

fix(web): open billing for the workspace that needs payment - #413

Merged
setkyar merged 2 commits into
mainfrom
fix/billing-402-request-workspace
Oct 5, 2026
Merged

setkyar merged 2 commits into
mainfrom
fix/billing-402-request-workspace

Conversation

@setkyar

@setkyar setkyar commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Problem

Creating or switching to a workspace without a plan could open the billing page of the previous workspace (mode=onboarding), leaving no way to pay for the new one.

During switchWorkspace(new) the URL still names the previous workspace, so WorkspaceRouteGuard switched straight back to it. A request sent for the new workspace then returned 402, and the redirect built its billing URL from the active workspace at response time — by then the previous one.

Changes

  • lib/api/client.ts — the 402 redirect uses the workspace from the request's X-Company-ID header (captured per request, including the 401-retry path), not the active workspace when the response lands.
  • WorkspaceRouteGuard.tsx — skip route reconciliation while a switch is in flight, so the guard no longer undoes it.

Testing

  • New regression test in client.test.ts: request sent for workspace A, active workspace changes to B before a 402 arrives → redirect targets A. Fails before the fix, passes after.
  • bun run build, biome, and the client/auth tests pass.
  • The guard change has no unit test: the existing component tests render statically and don't run effects.

…billed

The 402 redirect read the active workspace when the response arrived. During
a switch to a new, unpaid workspace the active workspace could already have
reverted to the previous one, so the user landed on the previous workspace's
billing page and could not pay for the new one. Redirect to the workspace
named in the request's X-Company-ID header instead.
While a switch is in flight the URL still names the previous workspace, and
the guard switched straight back to it. Wait for the switch to finish before
reconciling the route with the active workspace.
@setkyar
setkyar merged commit 1a76005 into main Oct 5, 2026
5 of 9 checks passed
@setkyar
setkyar deleted the fix/billing-402-request-workspace branch October 5, 2026 15:33
setkyar added a commit that referenced this pull request Oct 6, 2026
Opening the workspace chooser from a workspace that needs payment bounced
straight back to its billing page: the chooser still fires that workspace's
background requests, and their 402s triggered the billing redirect. The
chooser now never redirects to billing, and a 402 for a workspace the user
has already switched away from is ignored.

Ignoring stale 402s depends on WorkspaceRouteGuard no longer reverting a
switch in flight (#413); without that, a new workspace's 402 could arrive
after a revert and be dropped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant