jwtmiddleware

master
nima 2024-06-17 18:52:29 +03:30
parent 7ea71224f3
commit 0e534f5a2d
1 changed files with 26 additions and 0 deletions

View File

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