Fix login redirects

This commit is contained in:
ekzyis 2024-07-15 06:16:27 +02:00
parent 897d973b8d
commit 642e7785a1
2 changed files with 6 additions and 1 deletions

View File

@ -20,6 +20,11 @@ func HandleAuth(sc context.Context, action string) echo.HandlerFunc {
return LnAuth(sc, c, action)
}
// on session guard redirects to /login,
// we need to make sure that HTMX selects and targets correct element
c.Response().Header().Add("HX-Retarget", "#content")
c.Response().Header().Add("HX-Reselect", "#content")
return pages.Auth(mapAction(action)).Render(context.RenderContext(sc, c), c.Response().Writer)
}
}

View File

@ -47,7 +47,7 @@ func SessionGuard(sc context.Context) echo.MiddlewareFunc {
session := c.Get("session")
if session == nil {
// this seems to work for non-interactive and htmx requests
return c.Redirect(http.StatusTemporaryRedirect, "/login")
return c.Redirect(http.StatusSeeOther, "/login")
}
return next(c)
}