sharedb-access
Note
If you use nodejs
that doesn't support async/await
you need sharedb-access@3.0.0
Installation
- Install:
npm install sharedb-access
Usage
const shareDbAccess =
Using sharedb-access
you can control create
, read
, update
, and delete
database operation for every collection. You can use two types of rules:
allow
and deny
. By default all the operations are denied. So, you should
add some rules to allow them. If at least one allow
-rule allows the write, and
no deny
-rules deny the write, then the write is allowed to proceed.
You can call allow
and deny
-rules as many times as you like. The functions
should return true
if they think the operation should be allowed for allow
rules and denied for deny
-rules. Otherwise they should return false
, or
nothing at all (undefined
).
Create
// Allow create-operation for collection 'items' // docId - id of your doc for access-control// doc - document object// session - your connect session backend // Deny creation if user is not adminbackend // So, finally, only admins can create docs in 'items' collection// the same results is if you just write: backend
Read
Interface is like create
-operation
backend backend
Delete
Interface is like create
-operation
backend backend
Update
// docId - id of your doc for access-control// oldDoc - document object (before update)// newDoc - document object (after update)// ops - array of OT operations// session - your connect session const allowUpdateAll = async { return true} backend;