This project implements Role-Based Access Control (RBAC) in Node.js, providing a flexible and scalable solution for managing access permissions in your application.
- Define roles and permissions
- Assign roles to users
- Check permissions for specific actions
- Flexible and customizable configuration
To install the RBAC module, use npm:
npm install rbac-node
First, configure your roles and permissions in the rbac-config.js
file:
const rbacConfig = {
roles: {
admin: {
permissions: ['create', 'read', 'update', 'delete']
},
user: {
permissions: ['read']
}
}
};
const RBAC = require('rbac-node');
const rbac = new RBAC(rbacConfig);
rbac.addUserRoles(userId, ['admin']);
if (rbac.can(userId, 'create')) {
// Allow user to create
} else {
// Deny access
}
Check out the examples
directory for sample applications demonstrating RBAC usage in Node.js.
Contributions are welcome! If you'd like to contribute to this project, please follow these guidelines:
- Fork the repository
- Create a new branch (
git checkout -b feature
) - Make your changes
- Commit your changes (
git commit -am 'Add feature'
) - Push to the branch (
git push origin feature
) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.