Skip to content

fix(auth): clear MJ client-side caches on Auth0 logout#2185

Merged
bc-izygmunt merged 3 commits intonextfrom
ian-auth0-logout-cache-fix
Mar 22, 2026
Merged

fix(auth): clear MJ client-side caches on Auth0 logout#2185
bc-izygmunt merged 3 commits intonextfrom
ian-auth0-logout-cache-fix

Conversation

@bc-izygmunt
Copy link
Copy Markdown
Contributor

When a user logs out and a different user logs in, the second user could see stale metadata and cached data from the first user's session.

Root cause: Auth0's logout() only clears its own localStorage keys. MJ's IndexedDB cache (MJ_Metadata) and sessionId localStorage key survived logout, causing the next user to load the previous user's data.

Secondary bug: MJAuth0Provider.logout() was not subscribing to Auth0 Angular SDK v2's logout() Observable, so authState.refresh() never fired.

Changes:

  • MJAuth0Provider.logout() now clears all user-specific localStorage and deletes the MJ_Metadata IndexedDB before redirecting to Auth0 logout
  • Auth0 logout() Observable is now subscribed via firstValueFrom() so authState.refresh() fires correctly
  • GraphQLDataProvider.clearClientCache() static method added for apps that want to call cache clearing directly

Documented in Izzy: docs/mj-core-logout-cache-fix.md. Once this ships, IzzyAuth0Provider can be deleted and app.module.ts reverted to MJAuth0Provider.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 20, 2026

⚠️ No Changeset found

Latest commit: 425862d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@claude
Copy link
Copy Markdown

claude bot commented Mar 20, 2026

Claude finished @bc-izygmunt's task —— View job


SQL Migration Review Complete

Todo List:

  • Create pending pull request review
  • Check for SQL migration files in the PR
  • Submit review with findings

Summary: I've completed the review of this PR for SQL migration files. No SQL files were found in the migrations/ directory. The PR only contains TypeScript changes to the Auth0 provider service and GraphQL data provider, implementing client-side cache clearing on logout.

Since there are no SQL migration files with INSERT statements or spCreate calls to review, there's nothing to flag regarding the hard-coded UUID requirements.

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

SQL Migration Review Results

I've reviewed this PR for SQL migration files as requested.

No SQL migration files were found in this PR. The changes only include:

  • packages/Angular/Explorer/auth-services/src/lib/providers/mjexplorer-auth0-provider.service.ts - TypeScript service file
  • packages/GraphQLDataProvider/src/graphQLDataProvider.ts - TypeScript provider file

Since there are no SQL files in the migrations/ directory to review for hard-coded UUIDs in INSERT statements or spCreate calls, there's nothing to flag regarding the migration requirements.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 20, 2026

✅ Dependency Check Results

All dependencies are properly declared!

No missing dependencies detected in this PR.

@bc-izygmunt bc-izygmunt force-pushed the ian-auth0-logout-cache-fix branch from ec25925 to 55b7709 Compare March 20, 2026 17:16
Copy link
Copy Markdown
Contributor

@AN-BC AN-BC left a comment

Choose a reason for hiding this comment

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

LGTM - however, @bc-izygmunt I'd like @rkihm-BC to review this quickly as he just did something with MSAL so I want to ensure this isn't overlapping in some way with his work and we should make sure we fix this for all auth providers not just Auth0 or MSAL, we support many

Copy link
Copy Markdown

@rkihm-align rkihm-align left a comment

Choose a reason for hiding this comment

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

I think clearing the client-side cache on logout makes sense for all Authentication providers so it should be moved down to the base class with the ability to override to provide provider-specific behavior when necessary.

}

/**
* Clears MJ client-side caches (IndexedDB + localStorage) before logout so that
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The clearing of the client-side cache on logout should be something that's done regardless of the Auth provider. ie. Auth0, MSAL, Okta, etc. @bc-izygmunt, is this something that can be added to MJAuthBase and, if there are additional caches that need to be cleared specific to the Authentication provider, the method can be overridden in the provider?

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.

@rkihm-align agreed @bc-izygmunt can you make this change please and test with both MSAL and Auth0 and if that all works update PR and merge?

@bc-izygmunt bc-izygmunt force-pushed the ian-auth0-logout-cache-fix branch from 55b7709 to f5bba58 Compare March 22, 2026 19:14
bc-izygmunt and others added 3 commits March 22, 2026 14:52
When a user logs out and a different user logs in, the second user could
see stale metadata and cached data from the first user's session.

Root cause: Auth0's logout() only clears its own localStorage keys. MJ's
IndexedDB cache (MJ_Metadata) and sessionId localStorage key survived
logout, causing the next user to load the previous user's data.

Secondary bug: MJAuth0Provider.logout() was not subscribing to Auth0
Angular SDK v2's logout() Observable, so authState.refresh() never fired.

Changes:
- MJAuth0Provider.logout() now clears all user-specific localStorage and
  deletes the MJ_Metadata IndexedDB before redirecting to Auth0 logout
- Auth0 logout() Observable is now subscribed via firstValueFrom() so
  authState.refresh() fires correctly
- GraphQLDataProvider.clearClientCache() static method added for apps
  that want to call cache clearing directly

Documented in Izzy: docs/mj-core-logout-cache-fix.md. Once this ships,
IzzyAuth0Provider can be deleted and app.module.ts reverted to MJAuth0Provider.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…iders

Cache clearing on logout now happens in the base class so MSAL, Okta,
and any future providers get the same stale-data protection automatically.
Providers implement logoutInternal() for provider-specific logout only.
Adds unit tests covering cache clearing, key preservation, and call order.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add afterEach to vitest imports and update vi.fn generic syntax
from vi.fn<[], T>() to vi.fn<() => T>() for newer vitest versions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bc-izygmunt bc-izygmunt force-pushed the ian-auth0-logout-cache-fix branch from 336413f to 425862d Compare March 22, 2026 19:52
@bc-izygmunt bc-izygmunt merged commit 01abd70 into next Mar 22, 2026
3 checks passed
@bc-izygmunt bc-izygmunt deleted the ian-auth0-logout-cache-fix branch March 22, 2026 20:07
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.

3 participants