Files
customerTicket/static/js/customer-login-access.js
T
2026-10-14 12:27:55 +03:30

26 lines
921 B
JavaScript

(() => {
const script = document.querySelector('script[data-customer-login-access]');
if (!script) return;
let pending = false;
async function checkAccess() {
if (pending || document.hidden) return;
pending = true;
try {
const response = await fetch(script.dataset.customerLoginAccess, {
credentials: 'same-origin', cache: 'no-store', headers: {Accept: 'application/json'}
});
if (!response.ok) return;
const result = await response.json();
if (!result.authenticated) window.location.replace(result.login_url);
} catch (_) {
// Retry on the next heartbeat or when the browser returns online.
} finally {
pending = false;
}
}
window.setInterval(checkAccess, 10000);
document.addEventListener('visibilitychange', checkAccess);
window.addEventListener('pageshow', checkAccess);
window.addEventListener('online', checkAccess);
})();