-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix redundant event listeners and session cleanup #488
Conversation
The cause of this data corruption is: after successfully logging in and unlocking the keystore, the `useEffect` in `LocalStorageKeystore` calls `setCachedUsers` to update the cached users (to copy the `prfKeys` from the logged-in user's `privateData` to the matching cached user). But when there are two tabs open simultaneously, that code runs simultaneously in both tabs, and the `globalUserHandleB64u` is different between the two tabs. The user1 tab has `globalUserHandleB64u` set to the user handle of user1, and the user2 tab has `globalUserHandleB64u` set to the user handle of user2. So the result is that both cached users get updated with user2's `prfKeys`, which then causes the user to be logged into user2 even if they press the cache button labeled "Log in as user1".
Let's set aside the So let me clarify better the issues I was trying to address. Issue with Event ListenersWhen using
If we repeat steps 1 and 2 without reloading the tabs, tab_2 will no longer listen to the clean session event. This behavior forced us to remove the useEffect(() => {
// Add event listener
keystoreEvents.addEventListener('eventName', eventHandler);
// Cleanup event listener to prevent duplicates
return () => {
keystoreEvents.removeEventListener('eventName', eventHandler);
};
}, []); Preventing Circular Event CallsAnother issue arose when calling eventTarget.dispatchEvent(new CustomEvent(KeystoreEvent.Close)); This, in turn, calls Multiple Event Dispatch IssueLastly, we addressed an edge case in LocalStorageKeystore.ts. When a user clicks logout in one tab, the Now regarding the |
(See also reply in #489 (comment))
Hm, ok. I thought that it wouldn't actually behave like that because the |
b02e313
to
6c94f01
Compare
…etter reflect its purpose
541b21d
to
b86e169
Compare
This PR propose fixes for issues related to session management and logout synchronization across tabs ( pr #483 ), ensuring a consistent and optimized user experience.
Session Storage Cleanup
closeTabLocal
in order to send event only once in any case.Implementation Notes