As first encountered with https://github.com/markmhx/humans/issues/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
@agraebe is this something the DevX team may want to take on soon?
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
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).
It seems like this could be fixed with a sessionData.userData?.coreNode ?
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
@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.
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 what should be the next step for this issue?
@zone117x how much effort would it be to fix this bug? is this a ~P3?
@aulneau mind adding your workaround here in the meantime for reference?
@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.
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');
}
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?
@reedrosenbluth was this resolved in a particular PR?
@markmhx my bad, didn't mean to close this
Most helpful comment
It looks like changing this line https://github.com/blockstack/stacks.js/blob/7915c953d4b7c6a2d8e7a2f3125c449687ff8aac/packages/storage/src/storage.ts#L867
To
should at least fix the error being thrown that Mark first mentioned.
@marcosc90 is this something you could take on?