Skip to content

Commit

Permalink
vingo: don't redirect on unauthorized api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-dev committed Jun 16, 2024
1 parent cacc339 commit b6b9aac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions vingo/handlers/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ func IsLoggedIn(c *fiber.Ctx) error {
return c.Next()
}

func IsLoggedInAPI(c *fiber.Ctx) error {
if getUserFromStore(c) == nil {
return c.Status(401).SendString("Unauthorized")
}

return c.Next()
}

func IsAdmin(c *fiber.Ctx) error {
if !isAdmin(c) {
return c.Status(403).SendString("Forbidden")
Expand Down
2 changes: 1 addition & 1 deletion vingo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
logged.Post("/settings", handlers.SettingsUpdate)
}

api := logged.Group("/api", handlers.IsLoggedIn)
api := logged.Group("/api", handlers.IsLoggedInAPI)
{
api.Get("/user", handlers.User)
api.Get("/leaderboard", handlers.Leaderboard)
Expand Down

0 comments on commit b6b9aac

Please sign in to comment.