Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure availability of user profile data #314

Closed
dantrevino opened this issue Apr 3, 2020 · 10 comments
Closed

Ensure availability of user profile data #314

dantrevino opened this issue Apr 3, 2020 · 10 comments
Labels
bug Functionality broken

Comments

@dantrevino
Copy link

userData from userSession.loadUserData() does not work the same as the legacy blockstack.js methods.
With the previous auth I could let person = new blockstack.Person(userData) to get browser-set 'name' and 'avatar' profile data. ie. person.name() and person.avatarUrl().

With connect, the process above returns null for both person.name() and person.avatarUrl(), even if they exist.

This is a regression for those apps that want to allow some semblance of personalization.

@friedger
Copy link
Contributor

friedger commented Apr 5, 2020

The issue is that the legacy blockstack browser returns the profile in the authReponse token fetched from the profile url, while the new blockstack app/authenticator does not do this lookup.

Apps that still want to see the profile of a user should call lookup profile (http://blockstack.github.io/blockstack.js/globals.html#lookupprofile) I guess.

loadUserData still does the same, it loads the user data that is available in the local cache (localstorage) provided by the authenticator.

Interestingly, for apps that request publish_data the connect authenticator does return the profile.

@markmhendrickson
Copy link
Collaborator

@hstove thoughts on adding this support back in for single-player apps?

@markmhendrickson markmhendrickson changed the title User profile data not maintained Ensure availability of user profile data Apr 6, 2020
@markmhendrickson markmhendrickson added the bug Functionality broken label Apr 6, 2020
@dantrevino
Copy link
Author

@friedger using lookupProfile still does not give access to name() and avatarUrl() needed for personalization.

@friedger
Copy link
Contributor

friedger commented Apr 7, 2020

@dantrevino lookupProfile returns a promise of a profile with property name and image[i].contentUrl if provided by the user.

@dantrevino
Copy link
Author

@friedger I dont see it. What am I missing?

          const userData = userSession.loadUserData();
          const profile = blockstack.lookupProfile(userData.username);
          console.log("profile loaded: ", profile);
_proto__: Promise
constructor: ƒ Promise()
then: ƒ then()
catch: ƒ catch()
finally: ƒ finally()
Symbol(Symbol.toStringTag): "Promise"
__proto__: Object
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: Object
@type: "Person"
@context: "http://schema.org"
apps: {http://localhost:8080: "https://gaia.blockstack.org/hub/1AdqWQnAMsb8uQsrZy96G2P7HYd1zkpMnr/", https://reclaim.gg: "https://gaia.blockstack.org/hub/1PcbTDbgybtTjkETvo9j5jr92VFKJ4rwWC/", https://boom-money-daily.runkodapps.com: "https://gaia.blockstack.org/hub/19wdVbKFyNqVVSuJf8ppt8P92LjUMdJjpz/", https://noteriot-daily.runkodapps.com: "https://gaia.blockstack.org/hub/1Br9sxhdSw6xQJ3x8vvQNkuAz5X5oAq7a5/", https://runkod.com: "https://gaia.blockstack.org/hub/1NpdmvGsNyisR56CUiZHfZHnZukMYiSjJ5/", …}
api: {gaiaHubConfig: {…}, gaiaHubUrl: "https://hub.blockstack.org"}
__proto__:
constructor: ƒ Object()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
hasOwnProperty: ƒ hasOwnProperty()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toString: ƒ toString()
valueOf: ƒ valueOf()
toLocaleString: ƒ toLocaleString()
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()```

@friedger
Copy link
Contributor

friedger commented Apr 8, 2020

For missing profile details see #322

@hstove
Copy link
Contributor

hstove commented Apr 17, 2020

I've pushed a fix to the authenticator - there were some issues where we weren't properly fetching the profile before the authResponse. Please try this again, and let me know if you see the same issue.

@dantrevino
Copy link
Author

@hstove fyi, this is still not working using the class methods. i've made sure that my profile has a name and avatar:

https://gaia.blockstack.org/hub/1JE8MjzuSi19cBifCvrbsyAjx8PvwhakZp/profile.json

my sign in method:

    signIn() {
      const authOptions = {
        // The URL you want the user to be redirected to after authentication.
        redirectTo: "/wallet",
        manifestPath: "/manifest.json",
        sendToSignIn: true,
        finished: ({ userSession }) => {
          this.logInUser(userSession);
        },
        appDetails: {
          name: "Boom.Webby",
          icon: `${location.origin}/app-icon.png`,
        },
      };
      authenticate(authOptions);
    },

logInUser():

  logInUser(context, session) {
    console.log("user session: ", session);
    let userData = session.loadUserData();
    let person = new blockstack.Person(userData);
    userData.name = person.name();
    userData.avatar = person.avatarUrl();
    userData.authenticated = true;
    console.log("userData: ", userData);
    context.dispatch("setUser", userData);
  },

and the output of console.log() .. note the name and avatar are still null when using the class methods:

{username: "fibonacci.id", profile: {…}, email: null, decentralizedID: "did:btc-addr:1JE8MjzuSi19cBifCvrbsyAjx8PvwhakZp", identityAddress: "1JE8MjzuSi19cBifCvrbsyAjx8PvwhakZp", …}
appPrivateKey: (...)
authResponseToken: (...)
authenticated: (...)
avatar: null
coreSessionToken: (...)
decentralizedID: (...)
email: (...)
gaiaAssociationToken: (...)
hubUrl: (...)
identityAddress: (...)
name: null
profile: (...)
username: (...)

However, when i look at blockstack-session in Local Storage, the name and image props are there.

userData: {username: "fibonacci.id", profile: {@type: "Person", @context: "http://schema.org",…}, email: null,…}
appPrivateKey: "..."
.
.
.
profile: {@type: "Person", @context: "http://schema.org",…}
.
.
.
image: [{@type: "ImageObject", name: "avatar",…}]
name: "Fibonacci"
username: "fibonacci.id"
version: "1.0.0"

@hstove
Copy link
Contributor

hstove commented Apr 27, 2020

I dont see it. What am I missing?

@dantravino the problem here is that lookupProfile returns a Promise, and you're not using await. So, what you're getting back is a Promise.

Thanks for following up on the issue still persisting when you use the Person class - I'll look into that.

@hstove
Copy link
Contributor

hstove commented Apr 27, 2020

Hey @dantravino - looks like you need to just call new Person(userData.profile), instead of new Person(userData). Maybe it worked differently for you before? But this is in line with the docs here:

https://blockstack.github.io/blockstack.js/index.html#quickstart-build-an-application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality broken
Projects
None yet
Development

No branches or pull requests

5 participants