From af084321226b2adbe18c8a538435feda662cbad0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 25 Apr 2025 22:40:59 -0600 Subject: feat: add logout endpoint --- app/controllers/sessions/controller.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/controllers/sessions/controller.go') diff --git a/app/controllers/sessions/controller.go b/app/controllers/sessions/controller.go index 08002a2..7e706e7 100644 --- a/app/controllers/sessions/controller.go +++ b/app/controllers/sessions/controller.go @@ -25,6 +25,7 @@ func New(cfg *oidc.OpenID, http *http.Client) *Controller { func (c *Controller) MountTo(mux *http.ServeMux) { mux.HandleFunc("GET /session/new", c.New) mux.HandleFunc("GET /session/callback", c.Create) + mux.HandleFunc("POST /session/destroy", c.Destroy) } func (c *Controller) New(w http.ResponseWriter, r *http.Request) { @@ -138,3 +139,8 @@ func (c *Controller) Create(w http.ResponseWriter, r *http.Request) { http.SetCookie(w, cookie.New("session", encoded, tokens.Expiry)) http.Redirect(w, r, "/dashboard", http.StatusFound) } + +func (c *Controller) Destroy(w http.ResponseWriter, r *http.Request) { + cookie.Expire(w, r, "session") + http.Redirect(w, r, "/", http.StatusFound) +} -- cgit v1.2.3