Skip to content

Commit

Permalink
Merge branch 'main' into 893-bug-decrease-password-length-limit-to-12…
Browse files Browse the repository at this point in the history
…8-characters
  • Loading branch information
garrettladley authored May 24, 2024
2 parents 0030018 + b351533 commit 07859f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion backend/auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ type CustomClaims struct {
Role string `json:"role"`
}

type localsKey byte

const claimsKey localsKey = 0

// From extracts the CustomClaims from the fiber context
// Returns nil if the claims are not present
func From(c *fiber.Ctx) (*CustomClaims, error) {
rawClaims := c.Locals("claims")
rawClaims := c.Locals(claimsKey)
if rawClaims == nil {
return nil, utilities.Forbidden()
}
Expand All @@ -34,6 +38,10 @@ func From(c *fiber.Ctx) (*CustomClaims, error) {
return claims, nil
}

func SetClaims(c *fiber.Ctx, claims *CustomClaims) {
c.Locals(claimsKey, claims)
}

type JWTType string

const (
Expand Down
2 changes: 1 addition & 1 deletion backend/middleware/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (m *AuthMiddlewareService) Authenticate(c *fiber.Ctx) error {
// return errors.Unauthorized.FiberError(c)
// }

c.Locals("claims", claims)
auth.SetClaims(c, claims)

return nil
}(c)
Expand Down

0 comments on commit 07859f7

Please sign in to comment.