Skip to content

Commit

Permalink
fix: remove all timeouts when the redirection worked
Browse files Browse the repository at this point in the history
  • Loading branch information
CGNonofr authored and Loïc Mangeonjean committed Nov 21, 2022
1 parent c65342e commit cd2e033
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions oauth2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,40 @@ func (h *Handler) performOidcFrontOrBackChannelLogout(w http.ResponseWriter, r *
var total = {{ len .FrontChannelLogoutURLs }};
var redir = {{ .RedirectTo }};
var timeouts = [];
var redirected = false;
// Cancel all pending timeouts to avoid to call the frontchannel multiple times.
window.onbeforeunload = () => {
redirected = true;
for (var i=0; i<timeouts.length; i++) {
clearTimeout(timeouts[i]);
}
timeouts = [];
};
function setAndRegisterTimeout(fct, duration) {
if (redirected) {
return;
}
timeouts.push(setTimeout(fct, duration));
}
function redirect() {
window.location.replace(redir);
// In case replace failed try href
setTimeout(function () {
setAndRegisterTimeout(function () {
window.location.href = redir;
}, 250); // Show message after http-equiv="refresh"
}
function done() {
total--;
if (total < 1) {
setTimeout(redirect, 500);
setAndRegisterTimeout(redirect, 500);
}
}
setTimeout(redirect, 7000); // redirect after 5 seconds if e.g. an iframe doesn't load
setAndRegisterTimeout(redirect, 7000); // redirect after 5 seconds if e.g. an iframe doesn't load
// If the redirect takes unusually long, show a message
setTimeout(function () {
Expand Down

0 comments on commit cd2e033

Please sign in to comment.