tidy for blog post ;)

This commit is contained in:
Tom Moor
2021-07-22 13:43:29 -04:00
parent 3090c2cfa3
commit d35b5d2613

View File

@ -70,16 +70,18 @@ export default class AuthStore {
// signin/signout events in other tabs and follow suite. // signin/signout events in other tabs and follow suite.
window.addEventListener("storage", (event) => { window.addEventListener("storage", (event) => {
if (event.key === AUTH_STORE) { if (event.key === AUTH_STORE) {
// data may be null if key is deleted in localStorage
const data: ?PersistedData = JSON.parse(event.newValue); const data: ?PersistedData = JSON.parse(event.newValue);
// data may be null if key is deleted in localStorage
if (!data) return; if (!data) return;
// if there is no user on the new data then we know the other tab // If we're not signed in then hydrate from the received data, otherwise if
// signed out and we should do the same. Otherwise, if we're not // we are signed in and the received data contains no user then sign out
// signed in then hydrate from the received data if (this.authenticated) {
if (this.token && data.user === null) { if (data.user === null) {
this.logout(); this.logout();
} else if (!this.token) { }
} else {
this.rehydrate(data); this.rehydrate(data);
} }
} }