From 24ccf5da08b3ef551943bc7889e69b4a79eda03b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 29 May 2026 14:56:14 +0000 Subject: [PATCH] Fix profile update sync --- Client/src/pages/profile/view/Profile.tsx | 4 +-- Client/src/services/auth.service.ts | 35 +++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Client/src/pages/profile/view/Profile.tsx b/Client/src/pages/profile/view/Profile.tsx index f8d41b0..ed68f80 100644 --- a/Client/src/pages/profile/view/Profile.tsx +++ b/Client/src/pages/profile/view/Profile.tsx @@ -87,10 +87,10 @@ export default function Profile() { fetchProfile(); } }; - window.addEventListener('userUpdated', handleUserUpdate); + window.addEventListener('profile-updated', handleUserUpdate); return () => { - window.removeEventListener('userUpdated', handleUserUpdate); + window.removeEventListener('profile-updated', handleUserUpdate); }; }, [navigate, username, isOwnProfile, isLoaded, userId]); diff --git a/Client/src/services/auth.service.ts b/Client/src/services/auth.service.ts index b354a23..81e87f2 100644 --- a/Client/src/services/auth.service.ts +++ b/Client/src/services/auth.service.ts @@ -24,8 +24,38 @@ type AppUser = { username?: string | null } +type ProfileUpdateEventDetail = { + first_name?: string + last_name?: string + full_name?: string + username?: string + avatar_url?: string + bio?: string + address?: string +} + const getClerk = () => (typeof window !== 'undefined' ? (window as Window & { Clerk?: { user?: ClerkUser; session?: { signOut?: () => Promise }; signOut?: () => Promise } }).Clerk : undefined) +const isRecord = (value: unknown): value is Record => { + return typeof value === 'object' && value !== null +} + +const getProfileUpdateEventDetail = (value: unknown): ProfileUpdateEventDetail | undefined => { + if (!isRecord(value)) { + return undefined + } + + return { + first_name: typeof value.first_name === 'string' ? value.first_name : undefined, + last_name: typeof value.last_name === 'string' ? value.last_name : undefined, + full_name: typeof value.full_name === 'string' ? value.full_name : undefined, + username: typeof value.username === 'string' ? value.username : undefined, + avatar_url: typeof value.avatar_url === 'string' ? value.avatar_url : undefined, + bio: typeof value.bio === 'string' ? value.bio : undefined, + address: typeof value.address === 'string' ? value.address : undefined, + } +} + export const authService = { signUp: async (_data: unknown): Promise => { throw new Error('Please use Clerk component instead'); @@ -63,8 +93,9 @@ export const authService = { }, updateUser: (_userData: unknown): void => { - // Left empty. Profile modifications should happen via Clerk Dashboard or Clerk UI Components - console.warn('Profile modifications should be done via Clerk'); + if (typeof window === 'undefined') return; + const detail = getProfileUpdateEventDetail(_userData) + window.dispatchEvent(new CustomEvent('profile-updated', { detail })); }, forgotPassword: async (_data: unknown): Promise => {},