u
This commit is contained in:
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()
|
||||
|
||||
Reference in new issue
Block a user