fix server-initiated success redirect JS

This commit is contained in:
Andre Staltz 2021-04-09 18:09:12 +03:00 committed by cblgh
parent 28bded7c52
commit 02a1f8ab5b
1 changed files with 13 additions and 1 deletions

View File

@ -23,8 +23,20 @@ evtSource.addEventListener('failed', (e) => {
console.error(e.data);
});
let hasFocus = true;
window.addEventListener('blur', () => {
hasFocus = false;
});
evtSource.addEventListener('success', (e) => {
waitingElem.classList.add('hidden');
evtSource.close();
window.location = `/withssb/finalize?token=${e.data}`;
const redirectTo = `/withssb/finalize?token=${e.data}`
if (hasFocus) {
window.location.replace(redirectTo);
} else {
window.addEventListener('focus', () => {
window.location.replace(redirectTo);
});
}
});