-
Notifications
You must be signed in to change notification settings - Fork 6
/
Callback.js
53 lines (45 loc) · 1.38 KB
/
Callback.js
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
import React, { useEffect } from 'react';
import authConfig from '../authConfig';
const Callback = ({ auth, setAuth, userManager, userInfo, setUserInfo, handleLogout }) => {
useEffect(() => {
if (auth === null) {
userManager.signinRedirectCallback().then((user) => {
if (user) {
setAuth(true);
const access_token = user.access_token;
// Make a request to the user info endpoint using the access token
fetch(authConfig.userinfo_endpoint, {
headers: {
'Authorization': `Bearer ${access_token}`
}
})
.then(response => response.json())
.then(userInfo => {
setUserInfo(userInfo);
});
} else {
setAuth(false);
}
}).catch((error) => {
setAuth(false);
});
}
}, [auth, userManager, setAuth]);
if (auth === true && userInfo) {
return (
<div>
<h1>Welcome, {userInfo.name}!</h1>
<h2>Your ZITADEL Profile Information</h2>
<h3>Name: {userInfo.name}</h3>
<h3>Email: {userInfo.email}</h3>
<h3>Email Verified: {userInfo.email_verified? "Yes": "No"}</h3>
<h3>Locale: {userInfo.locale}</h3>
<button onClick={handleLogout}>Log out</button>
</div>
);
}
else {
return <div>Loading...</div>;
}
};
export default Callback;