Created
February 19, 2019 14:04
-
-
Save markmhendrickson/fb97fadc08425e31aed8eb1ee39ade29 to your computer and use it in GitHub Desktop.
hello hub 2
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
document.addEventListener("DOMContentLoaded", function(event) { | |
document.getElementById('signin-button').addEventListener('click', function(event) { | |
event.preventDefault() | |
const authRequest = blockstack.makeAuthRequest( | |
blockstack.generateAndStoreTransitKey(), | |
'http://localhost:5000/', | |
'http://localhost:5000/manifest.json', | |
['store_write', 'publish_data'], | |
'http://localhost:5000/', | |
blockstack.nextHour().getTime(), { | |
solicitGaiaHubUrl: true | |
} // new options param | |
); | |
blockstack.redirectToSignInWithAuthRequest(authRequest) | |
}) | |
document.getElementById('signout-button').addEventListener('click', function(event) { | |
event.preventDefault() | |
blockstack.signUserOut(window.location.href) | |
}) | |
function showProfile(profile) { | |
var person = new blockstack.Person(profile) | |
document.getElementById('heading-name').innerHTML = person.name() ? person.name() : "Nameless Person" | |
if(person.avatarUrl()) { | |
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()) { | |
var profile = blockstack.loadUserData().profile | |
showProfile(profile) | |
} else if (blockstack.isSignInPending()) { | |
blockstack.handlePendingSignIn().then(function(userData) { | |
window.location = window.location.origin | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment