onury / accesscontrol

Role and Attribute based Access Control for Node.js
https://onury.io/accesscontrol
MIT License
2.21k stars 178 forks source link

How the library persists data #76

Closed ChampIsMe closed 3 years ago

ChampIsMe commented 4 years ago

Hello @onury ,Great work here. I want to use this in production and I am requesting to know how the library persists data please.

ecasilla commented 4 years ago

From the docs it seems to be an in memory data set check the Readme.md

Fast. (Grants are stored in memory, no database queries.)

Ojooluwaseun commented 4 years ago

You can persist your grants in database and pass grants to AccessControl constructor as an array fetched from DB like so:

// grant list fetched from DB (to be converted to a valid grants object, internally)

let grantList = [ { role: 'admin', resource: 'video', action: 'create:any', attributes: ', !views' }, { role: 'admin', resource: 'video', action: 'read:any', attributes: '' }, { role: 'admin', resource: 'video', action: 'update:any', attributes: ', !views' }, { role: 'admin', resource: 'video', action: 'delete:any', attributes: '' }, { role: 'user', resource: 'video', action: 'create:own', attributes: ', !rating, !views' }, { role: 'user', resource: 'video', action: 'read:any', attributes: '' }, { role: 'user', resource: 'video', action: 'update:own', attributes: ', !rating, !views' }, { role: 'user', resource: 'video', action: 'delete:own', attributes: '' } ];

const ac = new AccessControl(grantList);