28 lines
377 B
Go
28 lines
377 B
Go
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)
|
|
}
|
|
}
|
|
|
|
|