26 lines
486 B
Go
26 lines
486 B
Go
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)
|
|
}
|
|
} |