UNPKG

blockstack

Version:

The Blockstack Javascript library for identity and authentication.

28 lines (25 loc) 1.07 kB
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 }) } })