10000 Notify other open tabs of updates to localStorage by tnorling · Pull Request #7550 · AzureAD/microsoft-authentication-library-for-js · GitHub
[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify other open tabs of updates to localStorage #7550

Merged
merged 16 commits into from
Feb 4, 2025

Conversation

tnorling
Copy link
Collaborator

In v4 we added encryption of localStorage entries, which also makes use of an in-memory cache to avoid constantly decrypting localStorage. This had the side effect of creating scenarios where multiple open tabs may have diverging cache states until they refresh and resync with localStorage. This PR adds broadcasting of localStorage updates to notify other open tabs or other instances of MSAL they should pull the latest changes into their respective in-memory cache objects.

On a related note: This PR also implements broadcasting for the Account Added and Account Removed events since these can no longer rely on the localStorage update events due to those values now being encrypted.

@github-actions github-actions bot added msal-browser Related to msal-browser package msal-common Related to msal-common package labels Jan 31, 2025
@github-actions github-actions bot added the documentation Related to documentation. label Feb 1, 2025
@github-actions github-actions bot added the samples Related to the samples apps for the library. label Feb 4, 2025
Co-authored-by: Jo Arroyo <joarroyo@microsoft.com>
@tnorling tnorling enabled auto-merge (squash) February 4, 2025 01:19
return;
}

if (context && context !== this.clientId) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it expected to reload if clientId changes? Is it not possible for multiple apps to be in same frame (some apps do this)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, the in-memory cache should contain only the cache entries that belong to its own clientId, it will ignore broadcasts coming from other clientIds. In the case where an app has multiple clientIds in the same frame each one will have its own listener and handle messages from its respective instance in the other tab.

Copy link
Member
@sameerag sameerag left a comment

Choose a reason for hiding this comment

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

Added one comment, can be addressed later

@github-actions github-actions bot added the msal-react Related to @azure/msal-react label Feb 4, 2025
@tnorling tnorling merged commit b2971df into dev Feb 4, 2025
8 checks passed
@tnorling tnorling deleted the localStorage-update-events branch February 4, 2025 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Related to documentation. msal-browser Related to msal-browser package msal-common Related to msal-common package msal-react Related to @azure/msal-react samples Related to the samples apps for the library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0