lets-go:11.5 logout

This commit is contained in:
tamsin johnson 2024-02-07 16:29:09 -08:00
parent 7aecca2131
commit 8a854768a0

View File

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