authorization added

master
nima 2024-06-17 19:06:02 +03:30
parent d1181f31a2
commit 40187810ad
1 changed files with 27 additions and 0 deletions

View File

@ -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)
}
}