Initial commit

This commit is contained in:
kandrusyak
2023-06-23 02:18:00 +03:00
commit 688ae61bc6
12 changed files with 297 additions and 0 deletions

26
mw/jwt.go Normal file
View 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")
},
})