pool-stats/web/logoutHandler.go
Pijus Kamandulis ef247fc843 Added auth
2025-07-04 21:05:28 +03:00

26 lines
494 B
Go

package web
import (
"net/http"
"time"
)
func (ws *WebServer) LogoutHandler(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie("session_id")
if err != nil {
http.Error(w, "No session found", http.StatusUnauthorized)
return
}
delete(ws.sessions, cookie.Value)
http.SetCookie(w, &http.Cookie{
Name: "session_id",
Value: "",
Path: "/",
HttpOnly: true,
Expires: <-time.After(time.Second * 1),
})
http.Redirect(w, r, "/", http.StatusSeeOther)
}