added logout route
This commit is contained in:
parent
9f280caafc
commit
20f95b8ea4
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user