From 1292d189cf15dd7ea904d5f76dc9630514f175c4 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 13 Jan 2025 10:11:20 +0100 Subject: feat(webui): implement logout process --- pkg/webui/sessions.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'pkg/webui/sessions.go') diff --git a/pkg/webui/sessions.go b/pkg/webui/sessions.go index 6d492d5..2d99871 100644 --- a/pkg/webui/sessions.go +++ b/pkg/webui/sessions.go @@ -22,16 +22,7 @@ func sessionsMiddleware(db *database.DB) func(http.Handler) http.Handler { } if err == nil { if len(cookie.Value) != 36 { - http.SetCookie(w, &http.Cookie{ - Name: cookieName, - Value: "", - Quoted: false, - Path: "/", - MaxAge: 0, // remove invalid cookie - HttpOnly: true, - SameSite: http.SameSiteStrictMode, - Secure: true, - }) + unsetSesssionCookie(w) } else { session, err := db.LoadSessionById(cookie.Value) if err != nil { @@ -53,3 +44,16 @@ func sessionsMiddleware(db *database.DB) func(http.Handler) http.Handler { }) } } + +func unsetSesssionCookie(w http.ResponseWriter) { + http.SetCookie(w, &http.Cookie{ + Name: cookieName, + Value: "", + Quoted: false, + Path: "/", + MaxAge: 0, // remove invalid cookie + HttpOnly: true, + SameSite: http.SameSiteStrictMode, + Secure: true, + }) +} -- cgit v1.2.3