diff --git a/_browser/hello-blockstack.md b/_browser/hello-blockstack.md index c16cb72d..73973ac8 100644 --- a/_browser/hello-blockstack.md +++ b/_browser/hello-blockstack.md @@ -212,23 +212,26 @@ All of the code in the file is wrapped in an event listener. ```js -document.addEventListener("DOMContentLoaded", function(event) { +document.addEventListener("DOMContentLoaded", event => { }) ``` This listener that waits until the DOM content is loaded. Then, it creates an auth request and redirects the user to sign in: ```js -document.getElementById('signin-button').addEventListener('click', function() { - blockstack.redirectUserToSignIn() +document.getElementById('signin-button').addEventListener('click', event => { + event.preventDefault() + userSession.redirectToSignIn() }) ``` -You can find the `redirectUserToSignIn()` function is part of the [Blockstack Javascript documentation](https://blockstack.github.io/blockstack.js/). There is also a sign out button handler. This handler deletes the local user data and signs the user out: +You can find the `redirectToSignIn()` function is part of the [Blockstack Javascript documentation](https://blockstack.github.io/blockstack.js/). There is also a sign out button handler. This handler deletes the local user data and signs the user out: ```js -document.getElementById('signout-button').addEventListener('click', function() { - blockstack.signUserOut(window.location.origin) +document.getElementById('signout-button').addEventListener('click', event => { + event.preventDefault() + userSession.signUserOut() + window.location = window.location.origin }) ``` @@ -236,7 +239,7 @@ The handlers are followed by a `showProfile()` function for showing the user's p ```js function showProfile(profile) { - var person = new blockstack.Person(profile) + let 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()) @@ -259,12 +262,14 @@ several states the user can be in: The application handles these situations as followed: ```js -var userSession = new UserSession() +const appConfig = new blockstack.AppConfig() +const userSession = new blockstack.UserSession({ appConfig: appConfig }) + if (userSession.isUserSignedIn()) { - var profile = userSession.loadUserData().profile - showProfile(profile) + const { profile } = userSession.loadUserData() + showProfile(profile) } else if (userSession.isSignInPending()) { - userSession.handlePendingSignIn().then(function(userData) { + userSession.handlePendingSignIn().then(userData => { window.location = window.location.origin }) }