fix: 'No tenant selected' error during onboarding - #372
Open
dimavedenyapin wants to merge 1 commit into
Open
Conversation
…selectTenant Three changes that fix the "No tenant selected" error during onboarding: 1. EnterpriseAuthError class with AuthErrorCode enum — typed errors propagated through IPC as "[CODE] message" so the renderer can do structured error handling instead of fragile string matching. 2. apiRequest 401-handler now checks if the error is already a typed EnterpriseAuthError (from executeRefresh) and propagates it directly instead of calling clearStoredData() a second time. This prevents the double-clear that nuked the JWT + tenant ID during selectTenant's fetchAndStoreAiGatewayVirtualKey sub-call. 3. Dashboard isAuthError() now checks structured codes first, with legacy string fallback for pre-migration errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dimavedenyapin
force-pushed
the
fix/tenant-auth-race-condition
branch
from
June 10, 2026 03:27
ed0f441 to
6af9348
Compare
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.
Summary
"No tenant selected — please select an organization"selectTenant()stores JWT + tenant ID, then callsfetchAndStoreAiGatewayVirtualKey(). If that call triggers a 401 retry that fails,apiRequest()'s catch block callsclearStoredData()— wiping the JWT and tenant ID that were just stored.selectTenant()catches this as a non-fatal warning, but the DB is already empty.What changed
1.
EnterpriseAuthErrorclass withAuthErrorCodeenum (enterprise-auth.ts)throw new Error(string)for all auth-related failuresSESSION_EXPIRED,NO_REFRESH_TOKEN,NO_TENANT,NOT_AUTHENTICATED,PERMISSION_DENIED,API_ERROR2. Prevent double
clearStoredData()(enterprise-auth.ts)executeRefresh()throws a typedEnterpriseAuthError(which already ranclearStoredData()if needed),apiRequest()'s 401-handler now propagates it directly instead of wrapping and clearing againselectTenant's sub-call3. IPC error code propagation (ipc-handlers.ts)
Error.message— custom fields are lostenterprise:apiRequesthandler now wrapsEnterpriseAuthErroras"[CODE] message"so the renderer gets structured codes4. Dashboard uses error codes (dashboard-store.ts)
isAuthError()now checks structured[CODE]prefixes firstTest plan
[SESSION_EXPIRED] Session expired...🤖 Generated with Claude Code