refactor: update user serialization in Yggdrasil handler to use SerializeUser for improved properties handling
Some checks failed
SonarQube Analysis / sonarqube (push) Has been cancelled
Some checks failed
SonarQube Analysis / sonarqube (push) Has been cancelled
This commit is contained in:
@@ -234,10 +234,8 @@ func Authenticate(c *gin.Context) {
|
|||||||
response.SelectedProfile = service.SerializeProfile(db, loggerInstance, redisClient, *selectedProfile)
|
response.SelectedProfile = service.SerializeProfile(db, loggerInstance, redisClient, *selectedProfile)
|
||||||
}
|
}
|
||||||
if request.RequestUser {
|
if request.RequestUser {
|
||||||
response.User = map[string]interface{}{
|
// 使用 SerializeUser 来正确处理 Properties 字段
|
||||||
"id": userId,
|
response.User = service.SerializeUser(loggerInstance, user, UUID)
|
||||||
"properties": user.Properties,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回认证响应
|
// 返回认证响应
|
||||||
|
|||||||
@@ -91,8 +91,23 @@ func SerializeUser(logger *zap.Logger, u *model.User, UUID string) map[string]in
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"id": UUID,
|
"id": UUID,
|
||||||
"properties": u.Properties,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 正确处理 *datatypes.JSON 指针类型
|
||||||
|
// 如果 Properties 为 nil,则设置为 nil;否则解引用并解析为 JSON 值
|
||||||
|
if u.Properties == nil {
|
||||||
|
data["properties"] = nil
|
||||||
|
} else {
|
||||||
|
// datatypes.JSON 是 []byte 类型,需要解析为实际的 JSON 值
|
||||||
|
var propertiesValue interface{}
|
||||||
|
if err := json.Unmarshal(*u.Properties, &propertiesValue); err != nil {
|
||||||
|
logger.Warn("[WARN] 解析用户Properties失败,使用空值", zap.Error(err))
|
||||||
|
data["properties"] = nil
|
||||||
|
} else {
|
||||||
|
data["properties"] = propertiesValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user