Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save markmhendrickson/fb97fadc08425e31aed8eb1ee39ade29 to your computer and use it in GitHub Desktop.
Save markmhendrickson/fb97fadc08425e31aed8eb1ee39ade29 to your computer and use it in GitHub Desktop.
hello hub 2
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