From 11fdfed0b9522c61fa2e91fc1356c7033d6904be Mon Sep 17 00:00:00 2001 From: "oppili.bsky.social" Date: Wed, 26 Mar 2025 09:59:09 +0000 Subject: [PATCH] fix 502 on logout my hunch is that this is caused by using a GET request, which browsers tend to cache sometimes. --- appview/auth/auth.go | 8 +++++++- appview/pages/templates/layouts/topbar.html | 7 ++++++- appview/state/router.go | 2 +- appview/state/state.go | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/appview/auth/auth.go b/appview/auth/auth.go index ff19196..a048c39 100644 --- a/appview/auth/auth.go +++ b/appview/auth/auth.go @@ -128,7 +128,13 @@ func (s *CreateSessionWrapper) GetStatus() *string { } func (a *Auth) ClearSession(r *http.Request, w http.ResponseWriter) error { - clientSession, _ := a.Store.Get(r, appview.SessionName) + clientSession, err := a.Store.Get(r, appview.SessionName) + if err != nil { + return fmt.Errorf("invalid session", err) + } + if clientSession.IsNew { + return fmt.Errorf("invalid session") + } clientSession.Options.MaxAge = -1 return clientSession.Save(r, w) } diff --git a/appview/pages/templates/layouts/topbar.html b/appview/pages/templates/layouts/topbar.html index cbd6c73..72d69ae 100644 --- a/appview/pages/templates/layouts/topbar.html +++ b/appview/pages/templates/layouts/topbar.html @@ -33,7 +33,12 @@ profile knots settings - logout + + logout + {{ end }} diff --git a/appview/state/router.go b/appview/state/router.go index 027ec3d..f9d549d 100644 --- a/appview/state/router.go +++ b/appview/state/router.go @@ -161,7 +161,7 @@ func (s *State) StandardRouter() http.Handler { r.Get("/", s.Timeline) - r.With(AuthMiddleware(s)).Get("/logout", s.Logout) + r.With(AuthMiddleware(s)).Post("/logout", s.Logout) r.Route("/login", func(r chi.Router) { r.Get("/", s.Login) diff --git a/appview/state/state.go b/appview/state/state.go index 7c83a10..4281820 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -165,7 +165,8 @@ func (s *State) Login(w http.ResponseWriter, r *http.Request) { func (s *State) Logout(w http.ResponseWriter, r *http.Request) { s.auth.ClearSession(r, w) - http.Redirect(w, r, "/login", http.StatusTemporaryRedirect) + w.Header().Set("HX-Redirect", "/login") + w.WriteHeader(http.StatusSeeOther) } func (s *State) Timeline(w http.ResponseWriter, r *http.Request) { -- knotmirror 0.0.1