Repository navigation
fix(web): open billing for the workspace that needs payment - #413
Merged
Merged
Conversation
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, soWorkspaceRouteGuardswitched 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'sX-Company-IDheader (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
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.