Realtime sync UI preferences between tabs
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user