fix: wechat verify

This commit is contained in:
Rogee
2025-01-10 19:44:24 +08:00
parent ab576706e7
commit 52c17b63bb
13 changed files with 83 additions and 92 deletions

View File

@@ -1,37 +1,27 @@
package middlewares
import (
"time"
"backend/app/consts"
"backend/app/errorx"
"github.com/gofiber/fiber/v3"
log "github.com/sirupsen/logrus"
)
func (f *Middlewares) ParseJWT(c fiber.Ctx) error {
tokens := c.GetReqHeaders()["Authorization"]
if len(tokens) == 0 {
queryToken := c.Query("token")
tokens = []string{queryToken}
if len(tokens) == 0 {
token := c.Cookies(consts.TokenTypeUser.String())
if token == "" {
token = c.Query("token")
if token == "" {
return c.Next()
}
}
token := tokens[0]
claim, err := f.jwt.Parse(token)
if err != nil {
c.Cookie(&fiber.Cookie{
Name: "token",
Value: "",
Expires: time.Now().Add(-1 * time.Hour),
HTTPOnly: true,
})
log.Errorf("failed to parse jwt from token: %s", token)
c.ClearCookie(consts.TokenTypeUser.String())
return errorx.Unauthorized
}
_ = claim
c.Locals("claim", claim)
return c.Next()
}