fix wxh5 jwt userid type

This commit is contained in:
2025-05-26 17:19:07 +08:00
parent 2962a0004d
commit 017ba9379b
3 changed files with 32 additions and 19 deletions

View File

@@ -2,6 +2,8 @@ package middleware
import (
"context"
"encoding/json"
"fmt"
"net/http"
"qnc-server/app/user/cmd/api/internal/config"
"qnc-server/common/ctxdata"
@@ -46,8 +48,10 @@ func (m *AuthInterceptorMiddleware) Handle(next http.HandlerFunc) http.HandlerFu
return
}
// 将用户ID添加到请求上下文
ctx := context.WithValue(r.Context(), ctxdata.CtxKeyJwtUserId, userId)
// 将用户ID转换为json.Number类型后添加到请求上下文
userIdStr := fmt.Sprintf("%d", userId)
userIdJsonNum := json.Number(userIdStr)
ctx := context.WithValue(r.Context(), ctxdata.CtxKeyJwtUserId, userIdJsonNum)
// 使用新的上下文继续处理请求
next(w, r.WithContext(ctx))