Skip to content

Commit

Permalink
[pocketbase#2726] removed unnecessary Dao().TotalAdmins() call
Browse files Browse the repository at this point in the history
  • Loading branch information
svekko authored Jun 16, 2023
1 parent d1bcaa6 commit caf343e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apis/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,17 @@ func RequireAdminAuth() echo.MiddlewareFunc {
func RequireAdminAuthOnlyIfAny(app core.App) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
admin, _ := c.Get(ContextAdminKey).(*models.Admin)
if admin != nil {
return next(c)
}

totalAdmins, err := app.Dao().TotalAdmins()
if err != nil {
return NewBadRequestError("Failed to fetch admins info.", err)
}

admin, _ := c.Get(ContextAdminKey).(*models.Admin)

if admin != nil || totalAdmins == 0 {
if totalAdmins == 0 {
return next(c)
}

Expand Down

0 comments on commit caf343e

Please sign in to comment.