Checking to see if a user is logged in, and logging a user our

This commit is contained in:
2024-07-22 10:00:17 +02:00
parent a0853cf880
commit 96f81418ec
5 changed files with 26 additions and 9 deletions

View File

@ -494,3 +494,11 @@ func (m *Repository) PostShowLogin(w http.ResponseWriter, r *http.Request) {
m.App.Session.Put(r.Context(), "flash", "Logged in successfully")
http.Redirect(w, r, "/", http.StatusSeeOther)
}
// Logout logs a user out
func (m *Repository) Logout(w http.ResponseWriter, r *http.Request) {
// TODO Use Redis to store the session. Check the documentation of scs package
m.App.Session.Destroy(r.Context())
m.App.Session.RenewToken(r.Context())
http.Redirect(w, r, "/user/login", http.StatusSeeOther)
}