From 810269454590fbed297f39bef654d6ca91e2ed46 Mon Sep 17 00:00:00 2001 From: garrettladley Date: Sun, 4 Feb 2024 19:21:05 -0500 Subject: [PATCH] ghwf debugging --- backend/src/errors/auth.go | 4 ---- backend/src/middleware/auth.go | 3 +++ backend/src/types/custom_claims.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/src/errors/auth.go b/backend/src/errors/auth.go index 37d9b1a8b..e53e5f03d 100644 --- a/backend/src/errors/auth.go +++ b/backend/src/errors/auth.go @@ -11,8 +11,4 @@ var ( StatusCode: fiber.StatusInternalServerError, Message: "failed to cast to custom claims", } - ExpectedClaimsButGotNil = Error{ - StatusCode: fiber.StatusInternalServerError, - Message: "expected claims but got nil", - } ) diff --git a/backend/src/middleware/auth.go b/backend/src/middleware/auth.go index fb05f6179..07fd76a61 100644 --- a/backend/src/middleware/auth.go +++ b/backend/src/middleware/auth.go @@ -26,6 +26,9 @@ func SuperSkipper(h fiber.Handler) fiber.Handler { err.FiberError(c) return false } + if claims == nil { + return false + } return claims.Role == string(models.Super) }) } diff --git a/backend/src/types/custom_claims.go b/backend/src/types/custom_claims.go index b475d96d7..c0351e0a0 100644 --- a/backend/src/types/custom_claims.go +++ b/backend/src/types/custom_claims.go @@ -14,7 +14,7 @@ type CustomClaims struct { func From(c *fiber.Ctx) (*CustomClaims, *errors.Error) { rawClaims := c.Locals("claims") if rawClaims == nil { - return nil, &errors.ExpectedClaimsButGotNil + return nil, nil } claims, ok := rawClaims.(*CustomClaims)