Sharing public data/page with "not logged in" users

I would like to enable sharing of certain pages of textlibrary to the public.
Using the multistorage usecase works fine as long as the visiting user is logged in to Blockstack.
Though if a user is not logged in, I get these errors:
Uncaught TypeError: Cannot read property 'hubUrl' of null

What do I need to change (maybe in the code below) so that the data would be accessible to the public?

As always… sorry for these newbie questions… any help is really appreciated.



For the React app I am currently using this code:

  fetchData() {
    this.setState({ isLoading: true })
    //hardcoded username -> just for this example//
    const username = "digitalwaveriding.id"
    const options = { username: username, decrypt: false, zoneFileLookupURL: 'https://core.blockstack.org/v1/names/' }
    getFile(textsFileName, options)
      .then((file) => {

        var arrTexts = JSON.parse(file || '[]');
        this.setState({
          arrTexts: arrTexts,
        })
      })
      .finally(() => {
        this.setState({ isLoading: false })
      })
    };

Hey man,

You will need to do a couple things:

A) Make sure when you run the putFile method, you have encrypt set to false
B) For the public page you might need to do a regular http request to the user’s Gaia bucket url and file pathname. I’m not 100% sure if getFile works for someone that’s not logged into blockstack.

2 Likes

Justin, thanks so much. Once again . :pray:
A) :white_check_mark:
B) I will try. Hoped it would work with getFile as well, would make the public/private user management slightly easier. Anyways… will try with a http request.
Thanks again for helping out! :facepunch:

If getFile doesn’t work for non logged in users, that’s a bug we should fix. Can you open an issue if it doesn’t work for you? https://github.com/blockstack/blockstack.js

2 Likes

Sure. Thanks so much for looking into it. https://github.com/blockstack/blockstack.js/issues/523