Hub-Api/services/authorization/role_check.go

28 lines
363 B
Go
Raw Permalink Normal View History

2024-06-17 19:06:02 +03:30
package authorization
import (
"netina/models"
2024-06-17 19:06:02 +03:30
"github.com/labstack/echo/v4"
)
func AdminRole(next echo.HandlerFunc)echo.HandlerFunc{
return func(c echo.Context)error{
user := c.Get("user").(*models.JWTClaims)
2024-06-17 19:06:02 +03:30
if user == nil {
return echo.ErrUnauthorized
}
if user.Role != "admin" {
return echo.ErrForbidden
}
return next(c)
}
}