tidy for blog post ;)

This commit is contained in:
Tom Moor 2021-07-22 13:43:29 -04:00
parent 3090c2cfa3
commit d35b5d2613
1 changed files with 9 additions and 7 deletions

View File

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