feat(webui): implement logout process

This commit is contained in:
Julien Dessaux 2025-01-13 10:11:20 +01:00
parent aef0b00fb9
commit 1292d189cf
Signed by: adyxax
GPG key ID: F92E51B86E07177E
5 changed files with 52 additions and 10 deletions

View file

@ -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,
})
}