28 lines
363 B
Go
28 lines
363 B
Go
package authorization
|
|
|
|
import (
|
|
"netina/models"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
|
|
|
|
func AdminRole(next echo.HandlerFunc)echo.HandlerFunc{
|
|
return func(c echo.Context)error{
|
|
user := c.Get("user").(*models.JWTClaims)
|
|
if user == nil {
|
|
return echo.ErrUnauthorized
|
|
}
|
|
|
|
if user.Role != "admin" {
|
|
return echo.ErrForbidden
|
|
}
|
|
|
|
|
|
return next(c)
|
|
}
|
|
}
|
|
|
|
|