summaryrefslogtreecommitdiff
path: root/app/controllers/sessions/controller.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-25 22:40:59 -0600
committermo khan <mo@mokhan.ca>2025-04-28 09:07:31 -0600
commitaf084321226b2adbe18c8a538435feda662cbad0 (patch)
tree3b7cfd6cce984ee43c0097c3b20ca9e73bb6a47a /app/controllers/sessions/controller.go
parent4030e9c36ebd22d2e9c647a1ba286390361b4f63 (diff)
feat: add logout endpoint
Diffstat (limited to 'app/controllers/sessions/controller.go')
-rw-r--r--app/controllers/sessions/controller.go6
1 files changed, 6 insertions, 0 deletions
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)
+}