1
0
forked from baron/baron-sso

fix(backend): fix syncLoginID to allow fields named 'id' to be synced from custom schema

This commit is contained in:
2026-04-01 13:03:39 +09:00
parent 27a7d226eb
commit 54a853a5c6

View File

@@ -1209,7 +1209,6 @@ func (h *UserHandler) UpdateUser(c *fiber.Ctx) error {
} }
} }
} }
finalLoginID := extractTraitString(traits, "id") finalLoginID := extractTraitString(traits, "id")
userEmail := extractTraitString(traits, "email") userEmail := extractTraitString(traits, "email")
userPhone := extractTraitString(traits, "phone") userPhone := extractTraitString(traits, "phone")
@@ -1583,7 +1582,7 @@ func extractTraitString(traits map[string]interface{}, key string) string {
// syncLoginID ensures that the 'id' trait (used as Kratos identifier) is in sync with the configured custom field. // syncLoginID ensures that the 'id' trait (used as Kratos identifier) is in sync with the configured custom field.
func syncLoginID(traits map[string]interface{}, metadata map[string]any, tenantID string, loginIDField string) { func syncLoginID(traits map[string]interface{}, metadata map[string]any, tenantID string, loginIDField string) {
if loginIDField == "" || loginIDField == "id" { if loginIDField == "" {
return return
} }
@@ -1608,7 +1607,9 @@ func syncLoginID(traits map[string]interface{}, metadata map[string]any, tenantI
} }
// 3. Check merged traits (which includes existing metadata) // 3. Check merged traits (which includes existing metadata)
if loginID == "" { // Important: Skip this if loginIDField is "id" because traits["id"] is the TARGET,
// and we don't want to sync "id" to "id" if we already checked metadata.
if loginID == "" && loginIDField != "id" {
// Existing trait (flat) // Existing trait (flat)
if val, ok := traits[loginIDField].(string); ok && val != "" { if val, ok := traits[loginIDField].(string); ok && val != "" {
loginID = val loginID = val