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) +}