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

Fix coreNode error when fetching public data with no user session #802

Closed
markmhendrickson opened this issue Jul 13, 2020 · 15 comments · Fixed by #1067
Closed

Fix coreNode error when fetching public data with no user session #802

markmhendrickson opened this issue Jul 13, 2020 · 15 comments · Fixed by #1067
Labels
bug Unwanted or unintended logic causing harm

Comments

@markmhendrickson
Copy link

As first encountered with markmhendrickson/humans#12, I'm getting TypeError: Cannot read property 'coreNode' of undefined upon calling getFile and reaching: https://github.com/blockstack/blockstack.js/blob/950dc4fc838099835ce0592f245453c770663b84/src/storage/index.ts#L253

sessionData.userData is undefined and throws an error instead of getting to use caller.appConfig.coreNode

cc @zone117x since he appears to be the last person to touch this part of the code

@markmhendrickson markmhendrickson self-assigned this Jul 13, 2020
@markmhendrickson markmhendrickson added the bug Unwanted or unintended logic causing harm label Jul 13, 2020
@markmhendrickson markmhendrickson removed their assignment Jul 13, 2020
@markmhendrickson markmhendrickson added this to the 2020 W29-W31 milestone Jul 15, 2020
@markmhendrickson
Copy link
Author

@agraebe is this something the DevX team may want to take on soon?

@markmhendrickson markmhendrickson removed this from the 2020 W29-W31 milestone Jul 15, 2020
@zone117x
Copy link
Member

Hmm, @markmhx can you provide a repo/snippet of code to easily reproduce? Looks like this is an easy fix but not entirely sure what the intention behind this code

@zone117x zone117x self-assigned this Jul 15, 2020
@zone117x zone117x added this to the 2020 W29-W31 milestone Jul 15, 2020
@markmhendrickson
Copy link
Author

markmhendrickson commented Jul 15, 2020

How about this as a snippet?

The intention is basically to query a user's public data using their ID without necessarily having a session oneself (e.g. for a public profile).

@hstove
Copy link
Contributor

hstove commented Jul 16, 2020

It seems like this could be fixed with a sessionData.userData?.coreNode ?

@markmhendrickson markmhendrickson removed this from the 2020 W29-W31 milestone Aug 5, 2020
@friedger
Copy link
Collaborator

This breaks the todo-list tutorial to lookup public lists for new users. https://docs.blockstack.org/authentication/building-todo-app#sign-out-and-see-your-public-tasks

@markmhendrickson
Copy link
Author

@agraebe It seems this was de-prioritized on the DevX side, correct? It seems like pretty core SDK functionality to me, so I'd suggest taking another look if we can.

@agraebe
Copy link
Contributor

agraebe commented Sep 18, 2020

I think this was never prioritized and we got started on the monorepo work in the meantime. @yknl could you take a look, please? maybe we could include this in the monorepo release?

@yknl yknl self-assigned this Oct 13, 2020
@yknl yknl linked a pull request Oct 20, 2020 that will close this issue
9 tasks
@agraebe
Copy link
Contributor

agraebe commented Jan 15, 2021

@yknl what should be the next step for this issue?

@agraebe
Copy link
Contributor

agraebe commented Apr 10, 2021

@zone117x how much effort would it be to fix this bug? is this a ~P3?

@markmhendrickson
Copy link
Author

@aulneau mind adding your workaround here in the meantime for reference?

@aulneau
Copy link
Contributor

aulneau commented Apr 12, 2021

@aulneau mind adding your workaround here in the meantime for reference?

The code snippet I provided is not actually a workaround for this specific issue.

@markmhendrickson
Copy link
Author

markmhendrickson commented Apr 13, 2021

If an app needs to retrieve data for a particular username without an active user session, might it cobble together a GET query for the data they want, constructing the file's path manually and initiate the request outside of the Stacks.js library somehow?

export async function fetchAppGaiaHubUrl(username: string): Promise<string | null> {
  const response = await fetch(`https://core.blockstack.org/v1/users/${username}`);
  const zonefile = await response.json(); // the users zonefile
 
  const app = APP_URL; // the app you're looking for, eg 'http://localhost:3000'
  const zone_file = Object.values(zonefile)?.[0] as any;
 
  // account for both legacy use and the new format from the extension
  if (zone_file?.profile.apps || zone_file?.profile.appsMeta) {
    if (zone_file.profile?.appsMeta?.[app]) {
      return zone_file.profile?.appsMeta?.[app].storage;
    }
    if (zone_file.profile?.apps?.[app]) {
      return zone_file.profile?.apps?.[app];
   }
  }
  throw Error('Cannot find zonefile');
} 

@zone117x
Copy link
Member

It looks like changing this line https://github.com/blockstack/stacks.js/blob/7915c953d4b7c6a2d8e7a2f3125c449687ff8aac/packages/storage/src/storage.ts#L867
To

 const configuredCoreNode = sessionData.userData?.coreNode || userSession.appConfig.coreNode;

should at least fix the error being thrown that Mark first mentioned.

@marcosc90 is this something you could take on?

@markmhendrickson
Copy link
Author

@reedrosenbluth was this resolved in a particular PR?

@reedrosenbluth
Copy link
Contributor

@markmhx my bad, didn't mean to close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unwanted or unintended logic causing harm
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants