@quaresma/rbac
v0.1.0
Published
A JS package to manage role-based access control (RBAC) that supports TypeScript and JSON serialization
Downloads
1
Maintainers
Readme
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")