-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfile.jsx
32 lines (24 loc) · 918 Bytes
/
Profile.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { useEffect, useState } from 'react';
import { ProfileData } from '../components/DataDisplay';
import { protectedResources } from '../authConfig';
import useGraphWithMsal from '../hooks/useGraphWithMsal'
export const Profile = () => {
const [graphData, setGraphData] = useState(null);
const { error, execute, result } = useGraphWithMsal({
scopes: protectedResources.graphMe.scopes,
}, protectedResources.graphMe.endpoint);
useEffect(() => {
if (!!graphData) {
return;
}
if (!graphData) {
execute(protectedResources.graphMe.endpoint).then((data) => {
setGraphData(data);
});
}
}, [graphData, execute, result]);
if (error) {
return <div>Error: {error.message}</div>;
}
return <>{graphData ? <ProfileData response={result} graphData={graphData} /> : null}</>;
};