Repository navigation
fix(api): only clear session on 401 for token-bearing requests, not background calls (#10750 A12) - #10794
Merged
Conversation
Contributor
✅ SSOT Configuration Compliance: Passing🎉 No hardcoded values detected that have SSOT config equivalents! |
This was referenced Jul 1, 2026
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.
Thinking Path
The user-frontend
ApiClientlogged the user out + redirected to/loginon any 401 (except/auth/endpoints). Load-time optional probes — the telemetry-consent check (/api/settings/telemetry) and version poll (/api/services/version) — fire before/without a valid session context and can 401. Those 401s are not a rejection of the user's session (no token was sent), yet they triggered the destructive clear+redirect, spuriously nuking a valid session (session-stability bug, umbrella A12).Root cause:
rawRequest()attaches the bearer token conditionally (_getAuthToken()→ only setsAuthorizationwhen a non-expired token exists), but the 401 branch ignored whether a token was actually attached. A token-less request that 401s has no session to invalidate.What Changed
autobot-frontend/src/utils/ApiClient.ts:rawRequest()now passesauthToken != null(whether this specific request carried anAuthorization: Bearerheader) into_handleUnauthorized(endpoint, tokenWasAttached)._handleUnauthorizedgained atokenWasAttachedparam. Whenfalse, it logs at debug level and returns early — no localStorage clear, no Pinia logout, no redirect./auth/skip; and for a genuinely authenticated request whose token is expired/invalid (tokenWasAttached === true), the full clear+redirect still fires (feat: Enable user authentication on autobot-user-frontend #827 / fix(auth): 401 loop from stale single_user localStorage in single_company mode #972 intent).No allowlist was added — the token-attached gate alone fully covers the background/optional-probe case, so an endpoint allowlist would be redundant surface area.
Verification
npx vue-tsc --noEmit -p tsconfig.app.json: 0 errors in ApiClient.ts. The only remaining errors (4) are all insrc/types/generated/api.ts(pre-existing base, tracked as vue-tsc-baseline red on Dev_new_gui: 6 pre-existing TS errors (config.apiUrl + stale generated api.ts) #10776) — this change adds none.npx eslint src/utils/ApiClient.ts: clean (exit 0, 0 warnings).ApiClient.tsis in the diff).Model Used
Opus 4.8 (1M context)
Part of #10750 (A12)