-
Notifications
You must be signed in to change notification settings - Fork 602
/
Copy pathindex.js
26 lines (20 loc) · 982 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// If the page delivers a logged-out content but we know from session storage
// that a user is logged-in, we force-refresh the page to bypass the cache,
// in order to get the logged-in content (with admin UI).
export default function() {
const isLoggedOutPageContent = !(apos.login && apos.login.user);
const isLoggedInCookie = apos.util.getCookie(`${self.apos.shortName}.loggedIn`) === 'true';
if (!isLoggedOutPageContent || !isLoggedInCookie) {
sessionStorage.setItem('aposRefreshedPages', '{}');
return;
}
const refreshedPages = JSON.parse(sessionStorage.aposRefreshedPages || '{}');
// Avoid potential refresh loops
if (!refreshedPages[location.href]) {
refreshedPages[location.href] = true;
sessionStorage.setItem('aposRefreshedPages', JSON.stringify(refreshedPages));
// eslint-disable-next-line no-console
console.info('Received logged-out content from cache while logged-in, refreshing the page');
location.reload();
}
};