Initial commit
This commit is contained in:
26
mw/jwt.go
Normal file
26
mw/jwt.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package mw
|
||||
|
||||
import (
|
||||
"astra-api-gateway/handler"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/labstack/echo-jwt/v4"
|
||||
"github.com/labstack/echo/v4"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var JWTMW = echojwt.WithConfig(echojwt.Config{
|
||||
SigningKey: []byte(handler.Key),
|
||||
Skipper: func(c echo.Context) bool {
|
||||
// Skip authentication for signup and login requests
|
||||
if strings.Contains(c.Path(), "auth") || c.Path() == "/health" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
SuccessHandler: func(c echo.Context) {
|
||||
user := c.Get("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
c.Request().Header.Set("UserId", claims["id"].(string))
|
||||
c.Request().Header.Del("Authorization")
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user