From 209555498f06d4029c66b955420574c1689ca2b9 Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Thu, 10 Aug 2023 23:43:41 +0200 Subject: [PATCH] clean: moved http.SetCookie into its own func --- api/auth.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/auth.go b/api/auth.go index ec321ac..5f1eda7 100644 --- a/api/auth.go +++ b/api/auth.go @@ -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) }