Skip to content

Commit

Permalink
📝 feat: set user in locals
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed Jun 10, 2024
1 parent 9f56803 commit 64d179b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/middleware/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"slices"
"time"

"github.com/GenerateNU/sac/backend/locals"
"github.com/GenerateNU/sac/backend/permission"

"github.com/GenerateNU/sac/backend/entities/models"
Expand Down Expand Up @@ -33,6 +34,7 @@ func (m *AuthMiddlewareHandler) Authorize(requiredPermissions ...permission.Perm
user := models.UnmarshalUser(strUser)

if user.Role == models.Super {
locals.SetUser(c, user)
return c.Next()
}

Expand All @@ -44,6 +46,7 @@ func (m *AuthMiddlewareHandler) Authorize(requiredPermissions ...permission.Perm
}
}

locals.SetUser(c, user)
return c.Next()
}
}
3 changes: 3 additions & 0 deletions backend/middleware/auth/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/GenerateNU/sac/backend/entities/clubs"
"github.com/GenerateNU/sac/backend/entities/models"
"github.com/GenerateNU/sac/backend/integrations/oauth/soth/sothic"
"github.com/GenerateNU/sac/backend/locals"
"github.com/GenerateNU/sac/backend/utilities"
"github.com/gofiber/fiber/v2"
)
Expand All @@ -29,6 +30,7 @@ func (m *AuthMiddlewareHandler) ClubAuthorizeById(c *fiber.Ctx, extractor Extrac
user := models.UnmarshalUser(strUser)

if user.Role == models.Super {
locals.SetUser(c, user)
return c.Next()
}

Expand All @@ -43,6 +45,7 @@ func (m *AuthMiddlewareHandler) ClubAuthorizeById(c *fiber.Ctx, extractor Extrac
}

if slices.Contains(clubAdmin, user.ID) {
locals.SetUser(c, user)
return c.Next()
}

Expand Down
2 changes: 2 additions & 0 deletions backend/middleware/auth/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/GenerateNU/sac/backend/entities/events"
"github.com/GenerateNU/sac/backend/entities/models"
"github.com/GenerateNU/sac/backend/integrations/oauth/soth/sothic"
"github.com/GenerateNU/sac/backend/locals"
"github.com/GenerateNU/sac/backend/utilities"

"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -41,6 +42,7 @@ func (m *AuthMiddlewareHandler) EventAuthorizeById(c *fiber.Ctx, extractor Extra
}

if slices.Contains(eventHostAdmin, user.ID) {
locals.SetUser(c, user)
return c.Next()
}

Expand Down
3 changes: 3 additions & 0 deletions backend/middleware/auth/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/GenerateNU/sac/backend/entities/models"
"github.com/GenerateNU/sac/backend/integrations/oauth/soth/sothic"
"github.com/GenerateNU/sac/backend/locals"
"github.com/GenerateNU/sac/backend/utilities"
"github.com/gofiber/fiber/v2"
)
Expand All @@ -27,6 +28,7 @@ func (m *AuthMiddlewareHandler) UserAuthorizeById(c *fiber.Ctx) error {
user := models.UnmarshalUser(strUser)

if user.Role == models.Super {
locals.SetUser(c, user)
return c.Next()
}

Expand All @@ -36,6 +38,7 @@ func (m *AuthMiddlewareHandler) UserAuthorizeById(c *fiber.Ctx) error {
}

if idAsUUID == &user.ID {
locals.SetUser(c, user)
return c.Next()
}

Expand Down

0 comments on commit 64d179b

Please sign in to comment.