Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Client/src/pages/profile/view/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
35 changes: 33 additions & 2 deletions Client/src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> }; signOut?: () => Promise<void> } }).Clerk : undefined)

const isRecord = (value: unknown): value is Record<string, unknown> => {
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<AuthResponse> => {
throw new Error('Please use Clerk <SignUp /> component instead');
Expand Down Expand Up @@ -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<void> => {},
Expand Down