blockstack
Version:
The Blockstack Javascript library for authentication, identity, and storage.
29 lines (26 loc) • 1.1 kB
JavaScript
/* eslint-disable */
document.addEventListener('DOMContentLoaded', function (event) {
document.getElementById('signin-button').addEventListener('click', function () {
var authRequest = blockstack.makeAuthRequest(null, window.location.hostname)
blockstack.redirectUserToSignIn(authRequest)
})
document.getElementById('signout-button').addEventListener('click', function () {
blockstack.signUserOut(window.location.origin)
})
function showProfile(profile) {
var person = new blockstack.Person(profile)
document.getElementById('heading-name').innerHTML = person.name()
document.getElementById('avatar-image').setAttribute('src', person.avatarUrl())
document.getElementById('section-1').style.display = 'none'
document.getElementById('section-2').style.display = 'block'
}
if (blockstack.isUserSignedIn()) {
blockstack.loadUserData(function (userData) {
showProfile(userData.profile)
})
} else if (blockstack.isSignInPending()) {
blockstack.signUserIn(function (userData) {
window.location = window.location.origin
})
}
})