@quaresma/rbac

0.1.0 • Public • Published

RBAC JS

A simple and easy RBAC library for JS.

  • Serializable
  • Support TypeScript

Usage

// Initialize RBAC with the roles, resources and permissions
const userRole = {
  id: "user",
  permissions: [{ action: "read", resource: "profile" }],
};
const adminRole = {
  id: "admin",
  permissions: [{
    action: "delete",
    resource: "users"
  }]
}
const rbac = new RBAC({
  resources: ["users"],
  actions: ["read", "delete"],
  roles: [userRole, adminRole],
});
// Load the user
const user = await db.getUserById("123")
const isPossible = rbac.can(user.role, "delete", "users")

Package Sidebar

Install

npm i @quaresma/rbac

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

5.5 kB

Total Files

5

Last publish

Collaborators

  • bruno.quaresma