From e05e85f8f8f9de36a67541ee05efe69d9a74c568 Mon Sep 17 00:00:00 2001 From: theandrew168 Date: Sun, 1 Sep 2024 17:59:29 -0500 Subject: [PATCH] Simplify sign out handler --- backend/web/page/signout.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/backend/web/page/signout.go b/backend/web/page/signout.go index c678079..7de9729 100644 --- a/backend/web/page/signout.go +++ b/backend/web/page/signout.go @@ -17,14 +17,15 @@ func HandleSignoutForm(store *storage.Storage) http.Handler { return } + // Delete the existing session cookie. + cookie := util.NewExpiredCookie(util.SessionCookieName) + http.SetCookie(w, &cookie) + // Lookup the session by it's client-side session ID. session, err := store.Session().ReadBySessionID(sessionID.Value) if err != nil { switch { case errors.Is(err, postgres.ErrNotFound): - // Delete the existing session cookie. - cookie := util.NewExpiredCookie(util.SessionCookieName) - http.SetCookie(w, &cookie) http.Redirect(w, r, "/", http.StatusSeeOther) default: http.Error(w, err.Error(), 500) @@ -37,9 +38,6 @@ func HandleSignoutForm(store *storage.Storage) http.Handler { if err != nil { switch { case errors.Is(err, postgres.ErrNotFound): - // Delete the existing session cookie. - cookie := util.NewExpiredCookie(util.SessionCookieName) - http.SetCookie(w, &cookie) http.Redirect(w, r, "/", http.StatusSeeOther) default: http.Error(w, err.Error(), 500) @@ -47,10 +45,6 @@ func HandleSignoutForm(store *storage.Storage) http.Handler { return } - // Delete the existing session cookie. - cookie := util.NewExpiredCookie(util.SessionCookieName) - http.SetCookie(w, &cookie) - // Redirect back to the index page. http.Redirect(w, r, "/", http.StatusSeeOther) })