Role Hierarchy
The system defines three distinct roles in theRole enum:
Role Structure
The platform enforces a clear organizational hierarchy:Supervisor-to-Officer Relationship
Credit Officers are linked to their Supervisors through thesupervisorId field in the User model:
A Supervisor can oversee multiple Credit Officers, while each Credit Officer reports to one Supervisor.
Permission Comparison
Here’s a comprehensive comparison of what each role can do:| Feature | Admin | Supervisor | Credit Officer |
|---|---|---|---|
| User Management | |||
| Create users | ✅ | ✅ | ❌ |
| Update any user | ✅ | ❌ | Self only |
| Delete users | ✅ | ❌ | ❌ |
| Reset passwords | ✅ | ❌ | ❌ |
| Union Management | |||
| Create unions | ✅ | ✅ | ❌ |
| View unions | ✅ | ✅ | Assigned only |
| Update unions | ✅ | ❌ | ❌ |
| Delete unions | ✅ | ❌ | ❌ |
| Reassign unions | ✅ | ❌ | ❌ |
| Member Management | |||
| Add members | ✅ | ✅ | ✅ |
| View members | ✅ | All supervised | Assigned only |
| Update members | ✅ | ✅ | ✅ |
| Delete members | ✅ | ❌ | ❌ |
| Loan Operations | |||
| Create loans | ✅ | ✅ | ✅ |
| View loans | ✅ | All supervised | Assigned only |
| Update loan details | ✅ | ✅ | ✅ |
| Approve/Reject loans | ✅ | ✅ | ❌ |
| Disburse loans | ✅ | ✅ | ❌ |
| Assign loans | ✅ | ✅ | ❌ |
| Delete loans | ✅ | ✅ | ✅ |
| Repayments | |||
| Record repayments | ✅ | ✅ | ✅ |
| View repayments | ✅ | All supervised | Assigned only |
| Reporting | |||
| Supervisor reports | ✅ | ✅ | ❌ |
| Officer performance | ✅ | ✅ | ❌ |
| System reports | ✅ | ❌ | ❌ |
| System Settings | |||
| Company settings | ✅ | ❌ | ❌ |
| Loan types | ✅ | ❌ | ❌ |
| Email templates | ✅ | ❌ | ❌ |
| Maintenance mode | ✅ | ❌ | ❌ |
| Backup/Restore | ✅ | ❌ | ❌ |
Middleware Implementation
The platform uses role-based middleware to enforce permissions:Data Access Scope
Admin
- Full visibility: Can access all data across all unions, members, and loans
- No restrictions: Bypasses all ownership checks
Supervisor
- Supervised territory: Can access data for all Credit Officers under their supervision
- Hierarchical access: Sees consolidated data from their team
- Approval authority: Can approve/reject loans from supervised officers
Credit Officer
- Assigned unions only: Can only access unions assigned to them via
creditOfficerId - Union members: Can only see members belonging to their assigned unions
- Own loans: Can only view and manage loans they created or are assigned to
Authentication & Authorization Flow
- Authentication: User identity is verified via JWT token or Supabase OAuth
- Role Check: User’s role is loaded from the
User.rolefield - Authorization: Middleware checks if user’s role is allowed for the endpoint
- Data Filtering: Controllers filter data based on role and ownership
Explore Role Details
Admin
Full system access with user management, system configuration, and global oversight
Supervisor
Team management, loan approval, and performance monitoring
Credit Officer
Day-to-day operations, member management, and loan processing
Best Practices
Principle of Least Privilege
Principle of Least Privilege
Always assign users the minimum role required for their job function. Don’t give Credit Officers supervisor access just for convenience.
Supervisor Assignment
Supervisor Assignment
When creating Credit Officers, always set their
supervisorId to establish the reporting relationship. This enables proper oversight and reporting.Union Assignment
Union Assignment
Ensure unions are properly assigned to Credit Officers through the
creditOfficerId field. This determines data access scope.Regular Audits
Regular Audits
Use the AuditLog model to track sensitive operations like user creation, role changes, and loan approvals.
