From 5223a44790f4e1f679ca705609a45940772b2318 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 17 Mar 2024 08:51:59 -0400 Subject: [PATCH] refactor: move DEFAULT_AUTH_COOKIE_NAME to account --- account/jwt.go | 2 ++ api/middleware/middleware.go | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/account/jwt.go b/account/jwt.go index 4843baf..6d5ee1b 100644 --- a/account/jwt.go +++ b/account/jwt.go @@ -11,6 +11,8 @@ import ( "github.com/golang-jwt/jwt/v5" ) +const AUTH_COOKIE_NAME = "auth_token" + type JWTPurpose string type VerifyTokenFunc func(claim *jwt.RegisteredClaims) error diff --git a/api/middleware/middleware.go b/api/middleware/middleware.go index 139f51a..a9913fe 100644 --- a/api/middleware/middleware.go +++ b/api/middleware/middleware.go @@ -16,7 +16,6 @@ import ( ) const DEFAULT_AUTH_CONTEXT_KEY = "user_id" -const DEFAULT_AUTH_COOKIE_NAME = "auth_token" type JapeMiddlewareFunc func(jape.Handler) jape.Handler type HttpMiddlewareFunc func(http.Handler) http.Handler @@ -76,7 +75,7 @@ func FindAuthToken(r *http.Request, cookieName string, queryParam string) string return cookie.Value } - if cookie, err := r.Cookie(DEFAULT_AUTH_COOKIE_NAME); cookie != nil && err == nil { + if cookie, err := r.Cookie(account.AUTH_COOKIE_NAME); cookie != nil && err == nil { return cookie.Value }