How to isolate a Gunjs database?

1.2k views Asked by At

I've been trying out GunJs for a couple of days now and I'm really enjoying it. As a starter project I've followed the Fireship chat dapp video aimed at building your own chat.

Here's the issue, now that I've finished the tutorial I would like to create my own chat. However, for some reason if I get a 'chat' node within my own app it seems to pick up on the same 'chat' node as the tutorial one that is online.

onMount(() => {

    // Get Messages in large chat
    db.get('chat')
    .map()
    .once(async (data, id) => {
        if (data) {
            // key for E2E - to do: change for web3
            const key = '#foo';

            var message = {
                //transform the data
                who: await db.user(data).get('alias'),
                what: (await SEA.decrypt(data.what, key)) + '',
                when: GUN.state.is(data, 'what'), 
            };

            if (message.what) {
                messages = [...messages.slice(-100), message]
            }
        }
    })
})

This is also the case if I change the encryption key (then the messages just become undefined). Multiple questions arise from this:

  • Are graph node names unique within the whole of GunDb?
  • How do you handle conflicts where two gun-based apps call on the same node name?
  • Is this problem generally solved through filtering using 'header' props?
  • How do I make it pick up on only my data?

Even if I've read most of the docs, there seems to be something I'm missing in my comprehension of how the graph is generally seperated between apps. Any insight on how this works would be much appreciated.

1

There are 1 answers

3
Yokowasis On BEST ANSWER

Are graph node names unique within the whole of GunDb?

Yes.

How do you handle conflicts where two gun-based apps call on the same node name?

You don't. The expected result will be, they will overwrite each other.

Is this problem generally solved through filtering using 'header' props?

I don't think it's the right way to do it.

How do I make it pick up on only my data?

Use your own relay server.

Conclusion : gunDB doesn't really care about the who fetch / put the data. If you want to protect your data, use your own relay server (not a public one), and put data in your user space. user space is readonly to the public, but read/write for the owner.