tidy for blog post ;)
This commit is contained in:
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user