User choice of Gaia hub now available during onboarding


#21

@hank I know it doesn’t work for existing users. My point is, an app developer has to account for those users in their code or it fails. How do I account for these users? I can’t simply assume that everyone that encounters my app is going to create or use totally new identity.

I want to the app to prompt those creating a new id for a Hub URL. Users who have an existing identity should just pass through to the app — and it should, of course, use that users pre-existing hub URL just fine.


#22

Ok. Chatted with @hank the solution was the position of the constant. Once I moved it to immediately before the redirectToSignInWithAuthRequest() the bam, it worked as I expected.

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
    })
  }
})