From 8a854768a082412096b8a8cf5714d445a54977d9 Mon Sep 17 00:00:00 2001 From: tamsin johnson Date: Wed, 7 Feb 2024 16:29:09 -0800 Subject: [PATCH] lets-go:11.5 logout --- snippetbox/cmd/web/handlers.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/snippetbox/cmd/web/handlers.go b/snippetbox/cmd/web/handlers.go index 169bd05..c9921f8 100644 --- a/snippetbox/cmd/web/handlers.go +++ b/snippetbox/cmd/web/handlers.go @@ -223,8 +223,14 @@ func (app *application) userLoginPost(w http.ResponseWriter, r *http.Request) { // userLoginPost ... func (app *application) userLogoutPost(w http.ResponseWriter, r *http.Request) { - id := app.sessionManager.PopInt(r.Context(), "authenticatedUserID") + err := app.sessionManager.RenewToken(r.Context()) + if err != nil { + app.serverError(w, r, err) + return + } + + app.sessionManager.Remove(r.Context(), "authenticatedUserID") + app.sessionManager.Put(r.Context(), "flash", fmt.Sprintf("You have been logged out.")) - app.sessionManager.Put(r.Context(), "flash", fmt.Sprintf("LOGGED OUT USER %d! (not really)", id)) http.Redirect(w, r, "/", http.StatusSeeOther) }