-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
16 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,15 @@ | ||
import passwordless from 'https://unpkg.com/@passwordless-id/connect' | ||
|
||
// the information requested from the profile | ||
const scope = 'openid avatar email' | ||
|
||
window.onClickSignIn = () => { | ||
// performs a redirect to let the user authenticate and/or authorize this app | ||
passwordless.auth({ scope }) | ||
} | ||
|
||
window.onClickSignOut = async () => { | ||
// performs a redirect to let the user sign out | ||
passwordless.logout() | ||
} | ||
import passwordless from 'https://unpkg.com/@passwordless-id/[email protected]/dist/connect.min.js' | ||
|
||
async function init() { | ||
// retrieves the user profile and `id_token` if available | ||
const user = await passwordless.id({ scope }) | ||
const user = await passwordless.id({ scope: 'openid avatar' }) | ||
if (user.signedIn && user.scopeGranted) { | ||
console.log(user) | ||
showUser(user) | ||
} | ||
else { | ||
showSignIn() | ||
document.getElementById('portrait').src = user.profile.picture | ||
document.getElementById('nickname').textContent = user.profile.nickname | ||
document.getElementById('sign-in').hidden = true | ||
document.getElementById('profile').hidden = false | ||
} | ||
} | ||
|
||
init() | ||
|
||
function showUser(user) { | ||
document.getElementById('picture').src = user.profile.picture | ||
document.getElementById('nickname').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 | ||
} | ||
init() |