From 9587ef4941dc6a7a0a07659b295e63750e0b1d13 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 17:12:31 -0400 Subject: [PATCH] refactor: require an api name to be provided and skip if not matched --- account/jwt.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/account/jwt.go b/account/jwt.go index 730c607..f4ae306 100644 --- a/account/jwt.go +++ b/account/jwt.go @@ -102,13 +102,17 @@ func JWTVerifyToken(token string, domain string, privateKey ed25519.PrivateKey, } func SetAuthCookie(jc jape.Context, jwt string, apiName string) { + if len(apiName) == 0 { + panic("apiName is required") + } + for name, api := range apiRegistry.GetAllAPIs() { routeableApi, ok := api.(router.RoutableAPI) if !ok { continue } - if len(apiName) > 0 && apiName != name { + if apiName != name { continue } @@ -125,13 +129,17 @@ func SetAuthCookie(jc jape.Context, jwt string, apiName string) { } func EchoAuthCookie(jc jape.Context, apiName string) { + if len(apiName) == 0 { + panic("apiName is required") + } + for name, api := range apiRegistry.GetAllAPIs() { routeableApi, ok := api.(router.RoutableAPI) if !ok { continue } - if len(apiName) > 0 && apiName != name { + if apiName != name { continue } @@ -168,13 +176,17 @@ func EchoAuthCookie(jc jape.Context, apiName string) { } func ClearAuthCookie(jc jape.Context, apiName string) { + if len(apiName) == 0 { + panic("apiName is required") + } + for name, api := range apiRegistry.GetAllAPIs() { routeableApi, ok := api.(router.RoutableAPI) if !ok { continue } - if len(apiName) > 0 && apiName != name { + if apiName != name { continue }