Getting "Error: gundb failed to authenticate user: Unverified data." when trying to create a folder in UserStorage
code:
import { Users, UserStorage } from '@spacehq/sdk'
const users = new Users({ endpoint: 'wss://auth-dev.space.storage' })
const identity = await users.createIdentity()
const user = await users.authenticate(identity)
const storage = new UserStorage(user)
await storage.createFolder({ bucket: 'bucket', path: 'pkg' })
error:
/home/v1rtl/Coding/x/node_modules/.pnpm/@[email protected]/node_modules/@spacehq/storage/dist/metadata/gundbMetadataStore.js:501
reject(new Error(`gundb failed to authenticate user: ${auth.err}`));
^
Error: gundb failed to authenticate user: Unverified data.
at Object.ack (/home/v1rtl/Coding/xnode_modules/.pnpm/@[email protected]/node_modules/@spacehq/storage/src/metadata/gundbMetadataStore.ts:579:20)
info:
@spacehq/sdk: 0.0.30- Node v16
Hi @talentlessguy , could you try this without the endpoint: 'wss://auth-dev.space.storage' and let us know how that goes? The value you currently have is a development sandbox and the problem with using that is there are other environment variables that are defaulted to match auth.space.storage which is the default so just overriding the endpoint would have a mismatch between that and the other env vars. This was because the dev sandbox was originally intended for internal use.
What we can maybe do is add a config flag called e.g., devMode: true that overrides all the variables to use the dev one so you can test in a non-prod setting. Will take this down as a feature request for now.
Another thing to note in your snippet is that before creating the folder, you would need to create a bucket called bucket first. This is because the initialization creates a default bucket called personal. So you can use that for subsequent operations or create a custom bucket if you want another bucket.
@jsonsivar thanks for responding!
I've tried to switch to this:
import { Users, UserStorage } from '@spacehq/sdk'
const users = new Users({ endpoint: 'wss://auth.space.storage' })
async function run() {
const identity = await users.createIdentity()
const user = await users.authenticate(identity)
const storage = new UserStorage(user)
await storage.createFolder({ bucket: 'bucket', path: 'pkg' })
console.log(await storage.listDirectory({ bucket: 'bucket', path: '.' }))
}
run()
it returns a new error:
reject(new Error(`gundb failed to authenticate user: ${auth.err}`));
^
Error: gundb failed to authenticate user: Unverified data.
at Object.ack (/home/v1rtl/Coding/x/node_modules/.pnpm/@[email protected]/node_modules/@spacehq/storage/src/metadata/gundbMetadataStore.ts:579:20)
I've got a few questions:
- Where do I get the API key from?
- Where should I pass it?
- How do I create a bucket in space.storage?
Hi @talentlessguy , I wasn't able to replicate this in my node environment. I realized you are on Node 16 so I will try upgrading to that and see if I can replicate it. In the meantime re: your other questions:
Where do I get the API key from?
You shouldn't need any API keys for this.
How do I create a bucket in space.storage?
The default bucket called personal is created so you can use that for now. We still need to expose the functionality to create arbitrary buckets.
@talentlessguy. I was able to reproduce this. The confusion was that our integration tests actually simulate the browser environment and so the SDK has only been tested and supported in a browser environment. I think there is an underlying issue with using Gun directly in NodeJS when using the SEA authenticated as we are. Found this but is a bit outdated https://github.com/amark/gun/issues/579. We will need to dig further and see if there is an issue with the library or if it's our code and will keep you posted.
@jsonsivar thanks for investigation! Glad that you figured out the root of the problem
by the way, I recommend to add integration tests for Nodejs as well because SDK should be usable with Node.js
Thats a great idea. We will try to add that in the next few weeks.
hey, gun just had an update that is up to date with master branch (0.2020.1232)
this means all bugfixes (including https://github.com/amark/gun/issues/579) are now in gun
could you please update to latest and run it through integration tests?
thanks in advance
Hmm, that was closed in 2018, I don't think it is the issue. 2020 had some regressions when browser/nodejs are not using same version, so try to match same version as the peers you are connecting to.