diff --git a/services/authorization/role_check.go b/services/authorization/role_check.go new file mode 100644 index 0000000..f75ccc3 --- /dev/null +++ b/services/authorization/role_check.go @@ -0,0 +1,27 @@ +package authorization + +import ( + j "netina/services/authentication" + + "github.com/labstack/echo/v4" +) + + + +func AdminRole(next echo.HandlerFunc)echo.HandlerFunc{ + return func(c echo.Context)error{ + user := c.Get("user").(*j.JWTClaims) + if user == nil { + return echo.ErrUnauthorized + } + + if user.Role != "admin" { + return echo.ErrForbidden + } + + + return next(c) + } +} + +