feat(webui): implement logout process
This commit is contained in:
parent
aef0b00fb9
commit
1292d189cf
5 changed files with 52 additions and 10 deletions
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue