refactor: require an api name to be provided and skip if not matched

This commit is contained in:
Derrick Hammer 2024-03-20 17:12:31 -04:00
parent 4a3028f61a
commit 9587ef4941
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 3 deletions

View File

@ -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
}