Realtime sync UI preferences between tabs

This commit is contained in:
Tom Moor
2024-04-17 19:50:42 -04:00
parent 30b7079508
commit 2d947fb56b
2 changed files with 41 additions and 17 deletions

View File

@@ -108,22 +108,21 @@ export default class AuthStore extends Store<Team> {
// signin/signout events in other tabs and follow suite.
window.addEventListener("storage", (event) => {
if (event.key === AUTH_STORE && event.newValue) {
const data: PersistedData | null | undefined = JSON.parse(
event.newValue
);
const newData: PersistedData | null = JSON.parse(event.newValue);
// data may be null if key is deleted in localStorage
if (!data) {
if (!newData) {
return;
}
// If we're not signed in then hydrate from the received data, otherwise if
// we are signed in and the received data contains no user then sign out
if (this.authenticated) {
if (data.user === null) {
if (newData.user === null) {
void this.logout(false, false);
}
} else {
this.rehydrate(data);
this.rehydrate(newData);
}
}
});