authorization added
parent
d1181f31a2
commit
40187810ad
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue