forked from ebhomengo/niki
24 lines
577 B
Go
24 lines
577 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||
|
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
||
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||
|
"github.com/labstack/echo/v4"
|
||
|
)
|
||
|
|
||
|
func BenefactorAuthorization(role entity.UserRole) echo.MiddlewareFunc {
|
||
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||
|
return func(c echo.Context) error {
|
||
|
claims := claim.GetClaimsFromEchoContext(c)
|
||
|
if claims.Role != role {
|
||
|
return c.JSON(http.StatusForbidden, echo.Map{"message": errmsg.ErrorMsgUserNotAllowed})
|
||
|
}
|
||
|
|
||
|
return next(c)
|
||
|
}
|
||
|
}
|
||
|
}
|