O3 Framework / userHasAccess
userHasAccess(
requiredPrivilege,user):boolean
Defined in: packages/framework/esm-api/src/current-user.ts:319
Checks whether the given user has access based on the required privilege(s). A user has access if they have the required privilege(s) or if they are a “System Developer” (super user). If no privilege is required, access is granted.
string | string[]
A single privilege string or an array of privilege strings that the user must have. If an array is provided, the user must have ALL privileges.
The user object containing their privileges and roles.
Role[]
boolean
true if the user has access, false otherwise. Returns true if no
privilege is required, and false if the user is undefined but a privilege is required.
import { userHasAccess } from '@openmrs/esm-api';
const hasAccess = userHasAccess('View Patients', currentUser);
const hasMultipleAccess = userHasAccess(['View Patients', 'Edit Patients'], currentUser);