Skip to content

Frontend/revoke tokens - #1790

Open
jsandoval81 wants to merge 4 commits into
csg-org:mainfrom
InspiringApps:frontend/revoke-token
Open

Frontend/revoke tokens#1790
jsandoval81 wants to merge 4 commits into
csg-org:mainfrom
InspiringApps:frontend/revoke-token

Conversation

@jsandoval81

@jsandoval81 jsandoval81 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Requirements List

  • None

Description List

  • Add Cognito /oauth2/revoke call to Logout page
    • Current call to Cognito /logout only removes cookies on the auth domain
  • Add UI styling to Logout page now that there is an async call waiting
  • Add tests to the Logout page
  • Update overall test runner to unmount wrappers so they don't continue to console log
    • Now that Logout page has non-trivial tests, the overall test suite started having noisier console log output as already-tested wrappers reacted to auth changes in the Logout tests.
    • The global unmount handling added resolved everything, except a case in the PrivilegePurchase page that also needed a small improvement

Testing List

  • yarn test:unit:all should run without errors or warnings
  • yarn serve should run without errors or warnings
  • yarn build should run without errors or warnings
  • Code review
  • Testing
    • Test client-side logout flow to confirm no regressions
    • Smoke test privilege purchase flow to confirm no regressions from tiny conditional check added

Closes #1743

Summary by CodeRabbit

  • New Features
    • Added a localized “Logging out...” message with a loading spinner on the logout screen.
    • Added Cognito refresh-token revocation with retry support as part of the logout flow.
    • Adjusted logout-route layout so page padding and main navigation display behave appropriately.
  • Bug Fixes
    • Prevented unnecessary privilege purchase flow checks when required data is missing.
    • Logout now continues even if token revocation fails, while recording relevant analytics.
  • Tests
    • Expanded logout and token-revocation test coverage, including retry/non-retry scenarios.
    • Improved test setup teardown to avoid cross-test UI cleanup issues.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Logout flow

Layer / File(s) Summary
Cognito token revocation
webroot/src/utils/auth.ts, webroot/src/utils/auth.spec.ts
Refresh tokens are revoked through Cognito using auth-specific configuration, retries, timeout handling, and tests for staff, licensee, cosmetology, missing-token, and failure cases.
Logout flow and progress UI
webroot/src/pages/Logout/*, webroot/src/components/Page/PageContainer/PageContainer.ts, webroot/src/locales/*, webroot/src/plugins/Statsig/statsig.plugin.ts
Logout displays localized progress feedback, hides navigation and top padding, revokes tokens before store cleanup, and records revocation failures through analytics.
Logout store completion
webroot/src/store/user/user.actions.ts, webroot/src/store/user/user.spec.ts
Logout state cleanup now dispatches directly without loading-state orchestration.

Privilege purchase navigation guard

Layer / File(s) Summary
Purchase-flow route guard
webroot/src/pages/PrivilegePurchase/PrivilegePurchase.ts
Purchase-flow handling is conditional on purchase eligibility and compact-type availability.

Test wrapper cleanup

Layer / File(s) Summary
Mounted wrapper teardown
webroot/tests/helpers/setup.ts
Mounted shallow and full wrappers are tracked and unmounted after each test, with fresh API mocks and restored Sinon state.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Logout
  participant revokeCognitoRefreshToken
  participant Cognito
  participant UserStore
  Logout->>revokeCognitoRefreshToken: Revoke refresh token
  revokeCognitoRefreshToken->>Cognito: POST /oauth2/revoke
  Cognito-->>revokeCognitoRefreshToken: Return revocation result
  Logout->>UserStore: Dispatch user/logoutRequest
  UserStore-->>Logout: Clear auth state and dispatch logoutSuccess
Loading

Possibly related PRs

Suggested reviewers: jlkravitz

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is short and relevant, referring to the frontend token revocation work, though it is a bit broad.
Description check ✅ Passed All required sections are present and the description covers the feature, styling, tests, and validation items.
Linked Issues check ✅ Passed The logout flow now calls Cognito /oauth2/revoke before clearing local state, satisfying #1743's session invalidation goal.
Out of Scope Changes check ✅ Passed The extra changes are supporting work for logout tests, UI, and test cleanup, with the PrivilegePurchase tweak noted in the PR scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@webroot/src/pages/Logout/Logout.ts`:
- Around line 131-136: Make revokeTokens treat a failed
revokeCognitoRefreshToken call as a logout failure: retry or report the
secure-login failure and prevent logoutRequest and window.location.replace from
running until revocation succeeds. Add a bounded timeout to the revocation
request in revokeCognitoRefreshToken, and update Logout.spec.ts to cover the
retry/error path instead of asserting that errors are swallowed.

In `@webroot/tests/helpers/setup.ts`:
- Around line 159-182: Update unmountAllWrappers so teardown failures are not
broadly swallowed: only ignore errors verified to indicate the wrapper is
already unmounted, while preserving or reporting all other errors. Continue
processing the remaining mountedWrappers after each attempt, and ensure the
registry removal does not make genuine unmount failures unrecoverable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7f2718f2-f506-44b4-bcb6-50e01d7f0efb

📥 Commits

Reviewing files that changed from the base of the PR and between faed2aa and b50f1b8.

📒 Files selected for processing (13)
  • webroot/src/components/Page/PageContainer/PageContainer.ts
  • webroot/src/locales/en.json
  • webroot/src/locales/es.json
  • webroot/src/pages/Logout/Logout.less
  • webroot/src/pages/Logout/Logout.spec.ts
  • webroot/src/pages/Logout/Logout.ts
  • webroot/src/pages/Logout/Logout.vue
  • webroot/src/pages/PrivilegePurchase/PrivilegePurchase.ts
  • webroot/src/store/user/user.actions.ts
  • webroot/src/store/user/user.spec.ts
  • webroot/src/utils/auth.spec.ts
  • webroot/src/utils/auth.ts
  • webroot/tests/helpers/setup.ts

Comment thread webroot/src/pages/Logout/Logout.ts Outdated
Comment thread webroot/tests/helpers/setup.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
webroot/src/utils/auth.spec.ts (1)

118-130: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover retry behavior for HTTP 5xx responses.

This test only exercises errors without response.status; a regression that removes the status >= 500 branch would still pass.

Proposed test
+    it('should retry server-side revoke failures', async () => {
+        const serverError = Object.assign(new Error('server'), { response: { status: 503 }});
+        axiosPostStub.onCall(0).rejects(serverError);
+        axiosPostStub.onCall(1).resolves({ data: {} });
+        authStorage.setItem(tokens.staff.REFRESH_TOKEN, 'staff-refresh-token');
+
+        await revokeCognitoRefreshToken(AppModes.JCC, AuthTypes.STAFF);
+
+        expect(axiosPostStub.callCount).to.equal(2);
+    });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@webroot/src/utils/auth.spec.ts` around lines 118 - 130, Update the “should
successfully retry retryable revoke failures then succeed” test to reject the
first two axiosPostStub calls with errors containing response.status values of
500 or higher, then resolve the third call. Keep the existing success assertion
and call-count verification so the test specifically covers the HTTP 5xx retry
path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@webroot/src/utils/auth.spec.ts`:
- Around line 118-130: Update the “should successfully retry retryable revoke
failures then succeed” test to reject the first two axiosPostStub calls with
errors containing response.status values of 500 or higher, then resolve the
third call. Keep the existing success assertion and call-count verification so
the test specifically covers the HTTP 5xx retry path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9015bb68-7716-43b9-b9b4-719d41bae679

📥 Commits

Reviewing files that changed from the base of the PR and between b50f1b8 and 1ac849c.

📒 Files selected for processing (6)
  • webroot/src/pages/Logout/Logout.spec.ts
  • webroot/src/pages/Logout/Logout.ts
  • webroot/src/plugins/Statsig/statsig.plugin.ts
  • webroot/src/utils/auth.spec.ts
  • webroot/src/utils/auth.ts
  • webroot/tests/helpers/setup.ts

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.

ASVS 3.0.1, Requirement 3.2 (server side token revocation)

1 participant