2024-01-17 07:46:57 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2024-09-10 20:55:19 +00:00
|
|
|
// nolint
|
2024-01-17 07:46:57 +00:00
|
|
|
func BenefactorAuthorization(role entity.UserRole) echo.MiddlewareFunc {
|
|
|
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
|
|
return func(c echo.Context) error {
|
|
|
|
claims := claim.GetClaimsFromEchoContext(c)
|
2024-01-25 11:43:39 +00:00
|
|
|
if claims.Role != role.String() {
|
2024-01-17 07:46:57 +00:00
|
|
|
return c.JSON(http.StatusForbidden, echo.Map{"message": errmsg.ErrorMsgUserNotAllowed})
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|