From 20f95b8ea41d1c768ca5b7fd8469cac18f6ea82f Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Sat, 18 Sep 2021 19:33:45 +0200 Subject: [PATCH] added logout route --- internal/httpServer.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/httpServer.go b/internal/httpServer.go index ed07a21..6f94e71 100644 --- a/internal/httpServer.go +++ b/internal/httpServer.go @@ -78,6 +78,8 @@ func initHttp(resolveContext context.Context, schema graphql.Schema, address str r.HandleFunc("/api/cookie", setLoginCookie).Methods("POST") + r.HandleFunc("/api/logout", logout).Methods("POST") + // Init the embedded static files initStatic(r) @@ -242,3 +244,19 @@ func setLoginCookie(rw http.ResponseWriter, r *http.Request) { rw.WriteHeader(http.StatusNoContent) } + +//logout removes the jwt cookie +func logout(rw http.ResponseWriter, r *http.Request) { + cookie := &http.Cookie{ + Name: "jwt", + Value: "", + Path: "/api", + Expires: time.Unix(0, 0), + HttpOnly: true, + SameSite: http.SameSiteStrictMode, + } + + http.SetCookie(rw, cookie) + + rw.WriteHeader(http.StatusNoContent) +}