Skip to content

zrrrzzt/gun-restrict-examples

Repository files navigation

Build Status js-standard-style Greenkeeper badge

gun-restrict-examples

Examples of how to restrict writes and still have public reads with GUN

NOT UPDATED

This is a bit out of sync at the moment. Maybe I'll fix it some day...

Use at your own risk :-)

Setup

Clone or download the repo.

cd into directory and run npm install

Restricted writes with SEA

Open a terminal and start the services

$ npm run sea

This will start 3 servers

  • The GUN server at localhost port 8000
  • The authenticated site on localhost port 3000
  • The unauthenticated site on localhost port 4000

Open your browser at http://localhost:3000

Login with whatever username/password you want. If the user doesn't exist it will be created.

Add some messages

Use the link to open the unathorized site

What to expect

Everything you write on the authenticated site will be synced to the unathenticated, but not the other way around.

Shut down the services with CTRL + C in the terminal

Restricted put with token example

Open a terminal and start the services

$ npm start

This will start 3 servers

  • The GUN server at localhost port 8000
  • The authenticated site on localhost port 3000
  • The unauthenticated site on localhost port 4000

Open 2 browsers.

What to expect

Everything you write on the authenticated site will be synced to the unathenticated, but not the other way around.

Explore more

If you want to se GUN in action without restrictions stop the running service pressing CTRL + C in the terminal.

Start an unrestricted GUN server.

$ npm run unrestricted

Now your sync will work both ways.

Acknowledgements

The solutions are based on an answer from stackoverflow, the SEA contact example and of course the GUN Gitter

License

MIT