From 17441ff674b48c4e21b5934dd44718e0542ccd3b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 16 Jan 2024 13:38:10 -0500 Subject: [PATCH] refactor: use setAuthCookie helper --- api/s5/http.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/api/s5/http.go b/api/s5/http.go index d0c93ec..472b535 100644 --- a/api/s5/http.go +++ b/api/s5/http.go @@ -346,16 +346,7 @@ func (h *HttpHandler) AccountRegister(jc jape.Context) { return } - authCookie := http.Cookie{ - Name: "s5-auth-token", - Value: jwt, - Path: "/", - HttpOnly: true, - MaxAge: int(time.Hour.Seconds() * 24), - Secure: true, - } - - http.SetCookie(jc.ResponseWriter, &authCookie) + setAuthCookie(jwt, jc) } func (h *HttpHandler) AccountLoginChallenge(jc jape.Context) { @@ -367,3 +358,16 @@ func (h *HttpHandler) AccountLogin(jc jape.Context) { //TODO implement me panic("implement me") } + +func setAuthCookie(jwt string, jc jape.Context) { + authCookie := http.Cookie{ + Name: "s5-auth-token", + Value: jwt, + Path: "/", + HttpOnly: true, + MaxAge: int(time.Hour.Seconds() * 24), + Secure: true, + } + + http.SetCookie(jc.ResponseWriter, &authCookie) +}