The Care Nexus LogoCareNexus Docs

Access Control

Role-based access control (RBAC), middleware enforcement, and route protection.

Updated June 2026 6 min read

The Care Nexus uses a multi-layer Role-Based Access Control (RBAC) system. Access is enforced at three levels: the API middleware layer, frontend route guards, and database query scoping. This defense-in-depth model ensures security even if one layer is bypassed.

Roles

RoleKey PermissionsCannot Access
patientOwn records, appointments, family data, AI chatOther patients' data, doctor management, clinic analytics
doctorOwn patients, prescriptions, schedule, revenueOther doctors' patients, clinic staff management
clinic_adminAll clinic doctors, staff, appointments, analyticsOther clinics' data, platform-wide users

Middleware Stack

authMiddleware

Every protected API route passes through authMiddleware which validates the JWT token. If invalid, expired, or missing, it returns 401 Unauthorized before reaching the controller. The decoded payload (userId, role) is attached to req.user.

roleMiddleware

roleMiddleware ensures that the user’s role matches the required role for the endpoint. For example, all /api/clinic/* routes require clinic_admin. Unauthorized access results in 403 Forbidden.

Frontend Route Guards

Layout components (DoctorLayout, PatientLayout, ClinicLayout) check the user role from localStorage on mount. If mismatched, the user is redirected to /login, preventing access to unauthorized dashboards.

Never trust the client

Frontend guards improve UX but do not provide security. All authorization is enforced on the backend for every request.