added logout route

This commit is contained in:
Djeeberjr 2021-09-18 19:33:45 +02:00
parent 9f280caafc
commit 20f95b8ea4

View File

@ -78,6 +78,8 @@ func initHttp(resolveContext context.Context, schema graphql.Schema, address str
r.HandleFunc("/api/cookie", setLoginCookie).Methods("POST") r.HandleFunc("/api/cookie", setLoginCookie).Methods("POST")
r.HandleFunc("/api/logout", logout).Methods("POST")
// Init the embedded static files // Init the embedded static files
initStatic(r) initStatic(r)
@ -242,3 +244,19 @@ func setLoginCookie(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(http.StatusNoContent) 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)
}