fix wxh5 jwt userid type

This commit is contained in:
2025-05-26 17:07:26 +08:00
parent 176ad00e35
commit beda62f833
3 changed files with 206 additions and 14 deletions

View File

@@ -2,6 +2,8 @@ package middleware
import (
"context"
"encoding/json"
"fmt"
"net/http"
"tydata-server/app/user/cmd/api/internal/config"
@@ -47,8 +49,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))