1
0
forked from baron/baron-sso

fix: 내 정보(UpdateMe) 수정 시 커스텀 필드 로그인 ID 동기화 및 Metadata 필드 추가 (#440)

This commit is contained in:
2026-03-25 16:28:19 +09:00
parent 6a4c37603d
commit aad4ea84a1
2 changed files with 38 additions and 4 deletions

View File

@@ -5266,6 +5266,39 @@ func (h *AuthHandler) UpdateMe(c *fiber.Ctx) error {
traits["department"] = req.Department
}
// Merge custom metadata into traits
if len(req.Metadata) > 0 {
for k, v := range req.Metadata {
// Do not overwrite core fields
if _, isCore := map[string]bool{"email": true, "phone_number": true, "name": true, "department": true, "grade": true, "companyCode": true, "affiliationType": true, "id": true, "role": true, "tenant_id": true}[k]; !isCore {
traits[k] = v
}
}
}
// [LoginID Sync based on Tenant Settings]
schemaCompCode := extractTraitString(traits, "companyCode")
if schemaCompCode != "" && h.TenantService != nil {
if tenant, err := h.TenantService.GetTenantBySlug(c.Context(), schemaCompCode); err == nil && tenant != nil {
if loginIDField, ok := tenant.Config["loginIdField"].(string); ok && loginIDField != "" {
// Search in Metadata (could be flat or namespaced)
if val, exists := req.Metadata[loginIDField]; exists {
if loginIDStr, ok := val.(string); ok && loginIDStr != "" {
traits["id"] = loginIDStr
}
} else if namespaced, exists := req.Metadata[tenant.ID]; exists {
if subMeta, ok := namespaced.(map[string]any); ok {
if val, exists := subMeta[loginIDField]; exists {
if loginIDStr, ok := val.(string); ok && loginIDStr != "" {
traits["id"] = loginIDStr
}
}
}
}
}
}
}
if err := h.updateKratosIdentity(identityID, traits); err != nil {
slog.Error("Failed to update profile in Kratos", "error", err)
return errorJSON(c, fiber.StatusInternalServerError, "프로필 업데이트에 실패했습니다.")