diff --git a/src/components/Player.tsx b/src/components/Player.tsx index 6ba2294e9020afd0145c5a39ab71a6378f7471f7..18c7d70f4da043d253c5d0ff44983a0549d1d80f 100644 --- a/src/components/Player.tsx +++ b/src/components/Player.tsx @@ -307,8 +307,34 @@ function AuthorizeHelper({ const pop = window.open(res.verification_url, "_blank"); if (pop) { pop.focus(); + let triggerReload = false; + let tries = 0; + const testAuth = () => { + tries++; + if (pop.closed || triggerReload || tries > 120) { + return; // this will be handled by the other interval + } + api.getAuthenticationStatus({ lecture_id: lecture.id }) + .then((res) => { + if (res.is_lecture_authenticated) { + triggerReload = true; + } else if ((res.in_progress_authentication ?? "").length === 0) { + console.log( + "Authentication appears to have been cancelled by the user", + ); + triggerReload = true; + } else { + setTimeout(testAuth, 1000); + } + }) + .catch((e) => { + console.error(e); + }); + }; + setTimeout(testAuth, 5000); let popInterval = setInterval(() => { - if (pop.closed) { + if (pop.closed || triggerReload) { + triggerReload = true; clearInterval(popInterval); reloadFunc(); }