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)