Added admin bool field and middleware.

This commit is contained in:
mikestefanello 2025-04-19 16:13:12 -04:00
parent dae9ea3ae1
commit 2c9cf2a21a
13 changed files with 183 additions and 5 deletions

View file

@ -103,3 +103,19 @@ func RequireNoAuthentication(next echo.HandlerFunc) echo.HandlerFunc {
return next(c)
}
}
// RequireAdmin requires that the user be an admin in order to proceed.
func RequireAdmin(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if u := c.Get(context.AuthenticatedUserKey); u != nil {
if user, ok := u.(*ent.User); ok {
if user.Admin {
// TODO tests
return next(c)
}
}
}
return echo.NewHTTPError(http.StatusUnauthorized)
}
}