fix: fully clear DA session on sign-out and enrich unauthorized errors#10
Merged
Conversation
Signing out (or recovering from a 401) only deleted the IMS token file. Site tokens, in-memory caches, and IMS session cookies in the persistent preview and preview-login partitions survived, so a previously signed-in user's session kept re-minting credentials and da:list failed with "Unauthorized: invalid or expired token" again after re-login. - invalidateDaSession (da-session.js) removes the token file, empties .site-tokens.json, resets token/preview caches, and clears IMS/DA cookies and web storage across the default, preview, and preview-login sessions; wired into da:logout and the 401 recovery path. - 401s now throw HttpRequestError with method, URL, x-error header, and body detail, still prefixed with the unauthorized message so existing detection matches; the main process appends site and IMS JWT diagnostics (client_id, user, issued/expires) and logs them. - Background requests no longer silently trigger a browser login on an expired token; the renderer shows why the session ended and routes to the explicit Sign in button. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
🎉 This PR is included in version 1.6.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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
After connecting, users hit
Error invoking remote method 'da:list': Error: Unauthorized: invalid or expired token— even after #9, and especially users who had signed in before.#9 cleared the
.da-token.jsonfile, but the app keeps credentials in four more places that all survived sign-out and 401 recovery:.site-tokens.json(+ its in-memory cache)persist:aem-preview-loginpartition (deliberately persistent so refreshes complete silently) and thepersist:aem-previewwebview partitionSo a previously signed-in user's IMS session kept silently re-minting credentials for the old account.
Changes
src/main/da-session.js):invalidateDaSessionremoves the token file, empties.site-tokens.json, resets token/preview caches, and clears IMS/DA cookies + web storage across the default, preview, and preview-login sessions. Runs on explicit sign-out and automatically on any 401.ContentApiClientnow throws anHttpRequestErrorcarrying method, URL, status,x-errorheader, and body detail — still prefixed withUnauthorized: invalid or expired tokenso existing detection keeps matching. The main process appends the site (org/repo+ backend) and IMS JWT diagnostics (client_id,user, issued/expires — never the token value) and logs the same line to the persisted log under theda-authscope.withContentClientresolves the stored token instead ofgetValidToken, so a background request with an expired token fails fast with the diagnostic error instead of popping a browser (also removes a port-9898 race under concurrent requests). The renderer shows "AEM sign-in expired or was rejected — sign in again" with the detail in the tooltip/console.If a user still hits a 401 after a truly fresh sign-in, the error now shows whether the token is stale (old
issuedtimestamp ⇒ cached somewhere) or fresh-but-rejected (⇒ da.live permissions for that org).Testing
test/da-session.test.js(token resolution errors, JWT diagnostics, storage clearing across partitions, full invalidation)test/content-api-client.test.jsnpm run lintandnpm testgreen (201 tests); dev app boots clean🤖 Generated with Claude Code