0.1.0 • Published 8 months ago

@quaresma/rbac v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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")