mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-07-01 18:22:28 +00:00
Merge pull request #693 from spartanz51/master
fix custom access controller example
This commit is contained in:
commit
66924be133
15
GUIDE.md
15
GUIDE.md
@ -280,6 +280,9 @@ await db.access.grant('write', identity2.publicKey) // grant access to identity2
|
|||||||
You can create a custom access controller by implementing the `AccessController` [interface](https://github.com/orbitdb/orbit-db-access-controllers/blob/master/src/access-controller-interface.js) and adding it to the AccessControllers object before passing it to OrbitDB.
|
You can create a custom access controller by implementing the `AccessController` [interface](https://github.com/orbitdb/orbit-db-access-controllers/blob/master/src/access-controller-interface.js) and adding it to the AccessControllers object before passing it to OrbitDB.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
let AccessControllers = require('orbit-db-access-controllers')
|
||||||
|
const AccessController = require('orbit-db-access-controllers/src/access-controller-interface')
|
||||||
|
|
||||||
class OtherAccessController extends AccessController {
|
class OtherAccessController extends AccessController {
|
||||||
|
|
||||||
static get type () { return 'othertype' } // Return the type for this controller
|
static get type () { return 'othertype' } // Return the type for this controller
|
||||||
@ -293,9 +296,17 @@ class OtherAccessController extends AccessController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async grant (access, identity) {} // Logic for granting access to identity
|
async grant (access, identity) {} // Logic for granting access to identity
|
||||||
|
|
||||||
|
async save () {
|
||||||
|
// return parameters needed for loading
|
||||||
|
return { parameter: 'some-parameter-needed-for-loading' }
|
||||||
|
}
|
||||||
|
|
||||||
|
static async create (orbitdb, options) {
|
||||||
|
return new OtherAccessController()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let AccessControllers = require('orbit-db-access-controllers')
|
|
||||||
AccessControllers.addAccessController({ AccessController: OtherAccessController })
|
AccessControllers.addAccessController({ AccessController: OtherAccessController })
|
||||||
|
|
||||||
const orbitdb = await OrbitDB.createInstance(ipfs, {
|
const orbitdb = await OrbitDB.createInstance(ipfs, {
|
||||||
@ -305,7 +316,7 @@ const orbitdb = await OrbitDB.createInstance(ipfs, {
|
|||||||
const db = await orbitdb.keyvalue('first-database', {
|
const db = await orbitdb.keyvalue('first-database', {
|
||||||
accessController: {
|
accessController: {
|
||||||
type: 'othertype',
|
type: 'othertype',
|
||||||
write: [id1.publicKey]
|
write: [id1.id]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user