@@ -2,6 +2,7 @@ package mildware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gen2d/internal/logger"
|
||||
@@ -45,7 +46,23 @@ func AuthMiddleware(jwtSecret string) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
if sub, ok := claims["sub"]; ok {
|
||||
c.Set("userID", sub)
|
||||
var userID uint
|
||||
switch v := sub.(type) {
|
||||
case float64:
|
||||
userID = uint(v)
|
||||
case int:
|
||||
userID = uint(v)
|
||||
case int64:
|
||||
userID = uint(v)
|
||||
case uint:
|
||||
userID = v
|
||||
case string:
|
||||
num, err := strconv.ParseUint(v, 10, 64)
|
||||
if err == nil {
|
||||
userID = uint(num)
|
||||
}
|
||||
}
|
||||
c.Set("userID", userID)
|
||||
}
|
||||
|
||||
c.Next()
|
||||
|
||||
+1
-1
@@ -213,7 +213,7 @@ POST /api/v1/prompt/optimize
|
||||
|
||||
## 工程管理
|
||||
|
||||
需认证。以下接口均需通过 Cookie 携带 Token,工程归属于当前登录用户。
|
||||
需认证。以下接口均需通过 `Authorization: Bearer <token>` 请求头携带 Token,工程归属于当前登录用户。
|
||||
|
||||
| 状态 | 方法 | 路径 | 说明 |
|
||||
|------|------|------|------|
|
||||
|
||||
Reference in New Issue
Block a user