Files
qvyun/backend/app/middlewares/m_jwt_parse.go
2025-01-10 19:44:24 +08:00

28 lines
479 B
Go

package middlewares
import (
"backend/app/consts"
"backend/app/errorx"
"github.com/gofiber/fiber/v3"
)
func (f *Middlewares) ParseJWT(c fiber.Ctx) error {
token := c.Cookies(consts.TokenTypeUser.String())
if token == "" {
token = c.Query("token")
if token == "" {
return c.Next()
}
}
claim, err := f.jwt.Parse(token)
if err != nil {
c.ClearCookie(consts.TokenTypeUser.String())
return errorx.Unauthorized
}
c.Locals("claim", claim)
return c.Next()
}