-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
70 lines (63 loc) · 2.27 KB
/
index.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
63
64
65
66
67
68
69
70
<html>
<head>
<link rel="manifest" href="manifest.json">
<script src="https://cdn.auth0.com/js/auth0-spa-js/2.1/auth0-spa-js.production.js"></script>
<title>PWA Test</title>
</head>
<body>
<h1>PWA Test</h1>
<p>
<button id="loginwithredirect">Login with redirect</button>
</p>
<p>
<button id="loginwithpopup">Login with popup</button>
</p>
<p>
<button id="logout">Logout</button>
</p>
<p id="result"></p>
<script>
;(async function(){
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("service_worker.js").then(function(registration) {
console.log("ServiceWorker:", registration.scope);
}).catch(function(err) {
console.error("ServiceWorker:", err);
})
}
const client = await auth0.createAuth0Client({
domain: "esd-test-omar.us.auth0.com",
clientId: "MwO3XcI5VXVbkv678cLiPTsCcUS8VRv8",
authorizationParams: {
redirect_uri: "https://omarquazi-okta.github.io/pwa-test/"
}
})
const handleLoginWithRedirect = async () => {
await client.loginWithRedirect()
}
const handleLoginWithPopup = async() => {
await client.loginWithPopup()
await displayUseIno()
}
const handleLogout = async () => {
await client.logout()
}
const displayUseIno = async () => {
const user = await client.getUser()
console.log(user)
if(user) {
const result = `Logged in: ${user.name}`
document.querySelector("#result").appendChild(document.createTextNode(result))
}
}
window.addEventListener('load', async () => {
const redirectResult = await client.handleRedirectCallback()
await displayUseIno()
})
document.querySelector("#loginwithredirect").addEventListener("click", handleLoginWithRedirect)
document.querySelector("#loginwithpopup").addEventListener("click", handleLoginWithPopup)
document.querySelector("#logout").addEventListener("click", handleLogout)
})()
</script>
</body>
</html>