-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvanilla.html
84 lines (69 loc) · 2.67 KB
/
vanilla.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<style>
body {
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 1rem;
background: linear-gradient(234deg,#75fa8b 0%,#48dfd2 100%) no-repeat;
}
</style>
</head>
<body>
<div id="spinner" class="spinner-border text-light" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<button id="sign-in" class="btn btn-light" onclick="onClickSignIn()" hidden>Sign In</button>
<section id="profile" class="card" style="width: 20rem; text-align: center;" hidden>
<div class="card-body">
<img src="https://ui.passwordless.id/avatars/finn.svg" style="height: 5rem"/>
<h1>Nickname</h1>
</div>
</section>
<section id="output" class="card container" hidden>
<div class="card-body">
<pre><code></code></pre>
</div>
</section>
<button id="sign-out" class="btn btn-light hidden" onclick="onClickSignOut()" hidden>Sign Out</button>
<script type="module">
import passwordless from './src/index.js'
const scope = 'openid avatar email'
window.onClickSignIn = () => {
passwordless.auth({scope})
}
window.onClickSignOut = async () => {
passwordless.logout()
}
async function init() {
const user = await passwordless.id({scope})
if(user.signedIn && user.scopeGranted) {
console.log(user)
showUser(user)
}
else {
showSignIn()
}
}
init()
function showUser(user) {
document.querySelector('#profile img').src = user.profile.picture
document.querySelector('#profile h1').textContent = user.profile.nickname
document.querySelector('#output code').textContent = JSON.stringify(user, null,' ')
document.getElementById('spinner').hidden = true
document.getElementById('profile').hidden = false
document.getElementById('output').hidden = false
document.getElementById('sign-out').hidden = false
}
function showSignIn() {
document.getElementById('spinner').hidden = true
document.getElementById('sign-in').hidden = false
}
</script>
</body>
</html>