Add sign out button

This commit is contained in:
2024-08-22 21:02:09 -04:00
parent dfde1b8381
commit 0fa9037164
4 changed files with 34 additions and 0 deletions

View File

@@ -92,6 +92,26 @@ func (u Users) PostSignin(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "User authenticated: %+v", user)
}
func (u Users) GetSignout(w http.ResponseWriter, r *http.Request) {
sessionCookie, err := r.Cookie("session")
if err != nil {
http.Redirect(w, r, "/signin", http.StatusFound)
return
}
err = u.SessionService.Delete(sessionCookie.Value)
if err != nil {
fmt.Println(err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
c := http.Cookie{
Name: "session",
MaxAge: -1,
}
http.SetCookie(w, &c)
http.Redirect(w, r, "/signin", http.StatusFound)
}
func (u Users) CurrentUser(w http.ResponseWriter, r *http.Request) {
seshCookie, err := r.Cookie("session")
if err != nil {