jwtmiddleware
parent
7ea71224f3
commit
0e534f5a2d
|
@ -0,0 +1,26 @@
|
|||
package middlewares
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
auth "netina/services/authentication"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func JWTMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
|
||||
|
||||
jwt := c.Request().Header.Get("Authorization")
|
||||
|
||||
claims, err := auth.ValidateUserToken(jwt)
|
||||
if err != nil {
|
||||
fmt.Println("Token validation error:", err)
|
||||
return echo.ErrUnauthorized
|
||||
}
|
||||
|
||||
//Store claims in the context
|
||||
c.Set("user", claims)
|
||||
return next(c)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue