MCPcopy Create free account
hub / github.com/cloudflare/meet / useUserMetadata

Function useUserMetadata

app/hooks/useUserMetadata.ts:12–41  ·  view source on GitHub ↗
(email: string)

Source from the content-addressed store, hash-verified

10}
11
12export function useUserMetadata(email: string) {
13 const { userDirectoryUrl } = useOutletContext<{ userDirectoryUrl?: string }>()
14 const search = new URLSearchParams({ email })
15
16 const key = `${userDirectoryUrl}?${search}`
17
18 const initialData: UserMetadata = {
19 displayName: email,
20 }
21
22 return useQuery({
23 initialData,
24 queryKey: [key],
25 queryFn: async ({ queryKey: [key] }) => {
26 if (userDirectoryUrl === undefined) return Promise.resolve(initialData)
27 const response = await fetch(key, { credentials: 'include' })
28
29 if (
30 response.headers.get('Content-Type')?.startsWith('application/json')
31 ) {
32 const parsedData: UserMetadata = (await response.json()) as any
33 return {
34 ...parsedData,
35 displayName: `${parsedData.firstName} ${parsedData.lastName}`,
36 }
37 }
38 return initialData
39 },
40 })
41}

Callers 5

UserListItemFunction · 0.90
MuteUserButtonFunction · 0.90
Participant.tsxFile · 0.90
IndexFunction · 0.90
UserJoinedOrLeftToastFunction · 0.90

Calls 1

fetchFunction · 0.85

Tested by

no test coverage detected