-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProfile.js
More file actions
53 lines (47 loc) · 1.45 KB
/
Profile.js
File metadata and controls
53 lines (47 loc) · 1.45 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { useState, useEffect } from 'react';
import environment from './environment';
const fetchUserInfo = async (token) => {
const res = await fetch(`${environment.OPServer}${environment.userInfoEndpoint}`, {
headers: {
authorization: `Bearer ${token}`
}
});
return res.json();
};
export const Profile = () => {
const [userInfo, setUserInfo] = useState(null);
useEffect(() => {
const fetchToken = localStorage.getItem('access_token');
fetchUserInfo(fetchToken)
.then((info) => {
console.log(info);
setUserInfo(info);
})
return () => {
}
}, [])
const DisplayUserInfo = () => {
return (
<div className="card text-white bg-success mb-3">
<div className="card-body">
<h5 className="card-title">Userinfo</h5>
<p className="card-text">{JSON.stringify(userInfo)}</p>
</div>
</div>
)
};
const UnAuthorized = () => {
return (
<div className="card text-white bg-danger mb-3">
<div className="card-body">
<h5 className="card-title">You are un authenticate!</h5>
</div>
</div>
)
};
return (
<div className="container mt-3">
{ userInfo ? <DisplayUserInfo /> : <UnAuthorized /> }
</div>
);
}