Skip to content

Instantly share code, notes, and snippets.

@sloev
Last active September 17, 2023 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sloev/031025ad5b886237cc996ef6987b65e2 to your computer and use it in GitHub Desktop.
Save sloev/031025ad5b886237cc996ef6987b65e2 to your computer and use it in GitHub Desktop.
gundb last test before quiting
(async () => {
const GUN = require('gun');
const suffix = Date.now()
require('gun/sea')
var SEA = GUN.SEA;
var gun = GUN()
async function auth( username, password ) {
return new Promise(( resolve, reject ) => {
gun.user()
.auth( username, password, ack =>
ack.err
? reject( ack.err )
: resolve( {
username:username,
sea:ack.sea,
pub: ack.sea.pub
})
)
})
}
async function createUser( username, password ) {
return await new Promise(( resolve, reject ) => {
gun.user().create( username, password, ack =>
ack.err
? reject( ack.err )
// Return authenticated user.
: resolve( auth( username, password ))
)
})
}
var serverAdmin = await createUser('admin'+suffix, 'lolCat1234')
// await gun.user().auth(serverAdmin)
var certificate = await SEA.certify("*", { "*": "users", "+": "*" }, serverAdmin.sea, null)
var bobSea = await createUser('bob'+suffix, 'lolCat1234')
// await gun.user().auth(bobSea)
var bobInfo = {
name: "bob",
username: "bob@bob.dk"
};
var bob = await gun.user(serverAdmin.pub).get('users').get(bobSea.pub).put(bobInfo, null, {opt: {cert: certificate }})
console.log(bob)
var aliceSea = await createUser('alice'+suffix, 'lolCat1234')
var aliceInfo = {
name: "alice",
username: "bob@bob.dk"
};
var alice = await gun.user(serverAdmin.pub).get('users').get(aliceSea.pub).put(aliceInfo, null)
console.log(alice)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment