clean: moved http.SetCookie into its own func

This commit is contained in:
Florian Sylvain
2023-08-10 23:43:41 +02:00
parent 61f221e49c
commit 209555498f
+5 -2
View File
@@ -126,7 +126,7 @@ func register(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write(message)
}
func logout(w http.ResponseWriter, _ *http.Request) {
func removeJwtCookie(w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: "jwt",
Value: "",
@@ -134,9 +134,12 @@ func logout(w http.ResponseWriter, _ *http.Request) {
MaxAge: -1,
Secure: false, // TODO false in dev, true in prod
HttpOnly: true,
Path: "/v1/",
Path: "/",
})
}
func logout(w http.ResponseWriter, _ *http.Request) {
removeJwtCookie(w)
message, _ := json.Marshal(map[string]interface{}{"message": "User logged out! HTTPonly jwt cookie deleted"})
_, _ = w.Write(message)
}