This commit is contained in:
oneao committed 2026-04-19 21:30:51 +08:00
1 parent b6415c0d65
commit 89aaef1d6b
29 files changed
+1118 -277

No files matched your search

@@ -1,7 +1,10 @@
package middleware
import (
"allapp-go/internal/httpx"
"allapp-go/pkg/jwtx"
"context"
"strings"
"github.com/gofiber/fiber/v3"
)
@@ -11,20 +14,18 @@ const CtxUserIDKey = "user_id"
// Auth 登录校验中间件
func Auth() fiber.Handler {
return func(c fiber.Ctx) error {
//token := strings.TrimSpace(c.Get("Token"))
//
//if token == "" {
// return httpx.Unauthorized(c, "未登录")
//}
//
//verifyToken, ok := jwtx.VerifyToken(c.Context(), token)
//if !ok {
// return httpx.Unauthorized(c, "登录已过期")
//}
//
//c.Locals(CtxUserIDKey, verifyToken.Data["user_id"])
token := strings.TrimSpace(c.Get("Token"))
ctx := context.WithValue(c.Context(), CtxUserIDKey, int64(779895419121733))
if token == "" {
return httpx.Unauthorized(c, "未登录")
}
verifyToken, ok := jwtx.VerifyToken(c.Context(), token)
if !ok {
return httpx.Unauthorized(c, "登录已过期")
}
ctx := context.WithValue(c.Context(), CtxUserIDKey, verifyToken.Data.UserID)
c.SetContext(ctx)
return c.Next()