Overview
MKing Admin implements a robust role-based access control (RBAC) system that controls user access to features and data throughout the application. The system uses permission slugs to enforce access rules at both the routing and UI levels.Architecture
Permission Storage
Permissions are stored in Zustand state management and persisted through JWT authentication:Permission Extraction
When a user logs in, their permissions are extracted from their assigned roles:Permission System
Available Permissions
Permissions are organized by module using a hierarchical slug structure:| Module | Permission Slug | Description |
|---|---|---|
| Home | home.panel | Access to dashboard |
| Products | products.view | View products |
| Catalogs | catalogs.manage | Manage product catalogs |
| Clients | clients.view | View client information |
| Quotations | quotations.admin.view | View admin quotations |
| Roles | roles.view | View and manage roles |
| Employees | employees.view | View employees |
| Users | users.view | Manage system users |
| Calendar | events.view | Access calendar |
Permission slugs follow the pattern
module.action (e.g., products.view, catalogs.manage)Creating Permissions
Permissions are created through the Permissions Manager interface:- Name: Display name (e.g., “View Users”)
- Slug: Unique identifier (e.g.,
users.view) - Module: Grouping category (e.g., “Usuarios”)
- Description: Optional explanation
Role Management
Creating Roles
Roles group multiple permissions together and are assigned to users:Define Role Information
Navigate to
/roles/create and provide:- Name: Role display name
- Slug: Unique identifier (cannot be changed after creation)
- Description: Optional role description
Select Permissions
Permissions are grouped by module. You can:
- Select individual permissions by checking them
- Select all permissions in a module by checking the module header
- The checkbox will show indeterminate state when some (but not all) module permissions are selected
Role API Endpoints
Role Protection
Permission Enforcement
Route Protection
Routes are protected using theProtectedRoute component:
ProtectedRoute component redirects unauthorized users:
Menu Visibility
The sidebar menu is dynamically filtered based on user permissions:Permission Checks in Components
Components can access permissions through the auth store:Permission Groups Component
ThePermissionGroup component displays permissions organized by module:
Best Practices
Permission Naming
Use consistent naming:
module.action pattern (e.g., users.view, products.create)Granular Permissions
Create specific permissions for different actions (view, create, edit, delete) rather than broad access
Module Grouping
Group related permissions under the same module for easier management
Role Hierarchy
Design roles from least to most privileged (e.g., Viewer → Editor → Admin)
Common Workflows
Adding a New Protected Feature
- Create Permission: Use Permissions Manager to add a new permission slug
- Update MenuSidebar: Add the permission to the relevant menu item in
src/core/MenuSidebar.tsx - Protect Routes: Ensure the route uses
ProtectedRoutewith the permission check - Update Roles: Assign the new permission to appropriate roles
Modifying User Access
- Navigate to Roles page (
/roles) - Edit the user’s assigned role
- Toggle permissions as needed
- Save the role - changes apply immediately to all users with that role
Users must log out and log back in for permission changes to take effect, as permissions are cached in the auth store during login.