Skip to content

Commit 324626a

Browse files
Fix htmx rendering the login page in frame on session logout (#29405)
- Fix #29391 With this change, htmx will not follow the redirect in the AJAX request but instead redirect the whole browser. To reproduce the bug fixed by this change without waiting a long time for the token to expire, you can logout in another tab then look in the original tab. Just make sure to comment out both instances of `window.location.href = appSubUrl` in the codebase so you won't be redirected immediately on logout. This is what I did in the following gifs. Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent 403766c commit 324626a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

modules/context/base.go

+8
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ func (b *Base) Redirect(location string, status ...int) {
265265
// So in this case, we should remove the session cookie from the response header
266266
removeSessionCookieHeader(b.Resp)
267267
}
268+
// in case the request is made by htmx, have it redirect the browser instead of trying to follow the redirect inside htmx
269+
if b.Req.Header.Get("HX-Request") == "true" {
270+
b.Resp.Header().Set("HX-Redirect", location)
271+
// we have to return a non-redirect status code so XMLHTTPRequest will not immediately follow the redirect
272+
// so as to give htmx redirect logic a chance to run
273+
b.Status(http.StatusNoContent)
274+
return
275+
}
268276
http.Redirect(b.Resp, b.Req, location, code)
269277
}
270278

0 commit comments

Comments
 (0)