-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.html
62 lines (56 loc) · 1.53 KB
/
profile.html
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
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<head>
<title>Corbado</title>
<link
rel="stylesheet"
href="https://unpkg.com/@corbado/web-js@latest/dist/bundle/index.css"
/>
<script src="https://unpkg.com/@corbado/web-js@latest/dist/bundle/index.js"></script>
</head>
<body>
<div>
<h1>Profile Page</h1>
<div>
<p id="info"></p>
<button id="auth-button"></button>
</div>
</div>
<script type="module">
await Corbado.load({
projectId: "pro-2796694128247001826",
})
const createButton = (text, clickHandler) => {
const buttonElement = document.getElementById('auth-button');
buttonElement.innerHTML = text;
buttonElement.onclick = clickHandler;
return buttonElement;
}
const addLoginButton = () => {
return createButton('Login', () => {
window.location.href = '/index.html';
})
}
const addLogoutButton = () => {
return createButton('Logout', async () => {
await Corbado.logout();
window.location.href = '/index.html';
})
}
if (!Corbado.user) {
// User is not authenticated
document.getElementById('info').innerHTML = `This content is only available to logged in
users. You can log in here:`
addLoginButton();
} else {
// User is authenticated
document.getElementById('info').innerHTML = `
User-ID: ${Corbado.user.sub}
<br/>
Email: ${Corbado.user.email}
`;
addLogoutButton();
}
</script>
</body>
</html>