Skip to content

Commit 8c68282

Browse files
apiFixFrontend
1 parent 3924e6d commit 8c68282

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/frontend/src/api/api.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,34 @@ export async function conversationApi (options: ConversationRequest, abortSignal
1717
}
1818

1919
export async function getUserInfo (): Promise<UserInfo[]> {
20-
const response = await fetch('/.auth/me')
21-
if (!response.ok) {
22-
console.log('No identity provider found. Access to chat will be blocked.')
23-
return []
20+
try {
21+
const response = await fetch('/.auth/me');
22+
if (!response.ok) {
23+
console.log('No identity provider found. Access to chat will be blocked.');
24+
return [];
25+
}
26+
27+
const payload = await response.json();
28+
29+
if (payload && payload.length > 0) {
30+
const userInfo: UserInfo = {
31+
access_token: payload[0].access_token || '',
32+
expires_on: payload[0].expires_on || '',
33+
id_token: payload[0].id_token || '',
34+
provider_name: payload[0].provider_name || '',
35+
user_claims: payload[0].user_claims || [],
36+
user_id: payload[0].user_claims?.find((claim: any) =>
37+
claim.typ === 'http://schemas.microsoft.com/identity/claims/objectidentifier'
38+
)?.val || payload[0].user_id || ''
39+
};
40+
return [userInfo];
41+
}
42+
43+
return payload;
44+
} catch (e) {
45+
console.error('Error fetching user info:', e);
46+
return [];
2447
}
25-
26-
const payload = await response.json()
27-
return payload
2848
}
2949

3050
export const frontendSettings = async (): Promise<Response | null> => {

0 commit comments

Comments
 (0)