From 9c959b259c25a591be9ae26caac0a0a4467f7720 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Sun, 30 Dec 2018 06:34:30 -0500 Subject: Improve logout --- main.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index a5de4dc..174a610 100644 --- a/main.go +++ b/main.go @@ -87,13 +87,17 @@ func (app *App) loginHandler(w http.ResponseWriter, r *http.Request) { } func (app *App) logoutHandler(w http.ResponseWriter, r *http.Request) { - c := http.Cookie{ - Name: "id", - Value: "", - Domain: "." + app.Domain, - MaxAge: 0, + if s, ok := app.validate(r); ok { + // should we save old sessions in another table? + app.DeleteSession(s.Id) + c := http.Cookie{ + Name: "id", + Value: "", + Domain: "." + app.Domain, + MaxAge: -1, + } + http.SetCookie(w, &c) } - http.SetCookie(w, &c) http.Redirect(w, r, "/login", http.StatusSeeOther) } -- cgit v1.2.3-70-g09d2