diff --git a/backend/internal/handler/auth_handler.go b/backend/internal/handler/auth_handler.go index 2c0e3857..3a6adbd1 100644 --- a/backend/internal/handler/auth_handler.go +++ b/backend/internal/handler/auth_handler.go @@ -5283,20 +5283,27 @@ func (h *AuthHandler) UpdateMe(c *fiber.Ctx) error { 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 != "" { + slog.Debug("[UpdateMe] Login ID sync active", "field", loginIDField) // Search in Metadata (could be flat or namespaced) + var newLoginID string if val, exists := req.Metadata[loginIDField]; exists { - if loginIDStr, ok := val.(string); ok && loginIDStr != "" { - traits["id"] = loginIDStr + if s, ok := val.(string); ok { + newLoginID = s } } 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 s, ok := val.(string); ok { + newLoginID = s } } } } + + if newLoginID != "" { + slog.Info("[UpdateMe] Syncing custom field to LoginID", "field", loginIDField, "value", newLoginID) + traits["id"] = newLoginID + } } } }