This example demonstrates the core functionality of the React Access Control package with a simple React application.
- Permission-based access control
- Feature flag system
- Conditional rendering with
AccessGuard - Programmatic access checks with
useAccessControlhook - User authentication simulation
- Custom storage adapter usage
# Install dependencies
npm install
# Start the development server
npm startThe example includes a simple login system that allows you to test different user roles:
- Viewer: Only has
READ_USERSpermission - Editor: Has
READ_USERSandWRITE_USERSpermissions - Admin: Has all permissions including
ACCESS_ADMIN
- User List: Always visible to users with
READ_USERSpermission - Add/Edit Buttons: Only visible with
WRITE_USERSpermission - Delete Button: Only visible with
DELETE_USERSpermission - Admin Panel: Only visible with
ACCESS_ADMINpermission
- New UI: Shown when
NEW_UIfeature flag is enabled - Beta Features: Shown when
BETA_FEATURESfeature flag is enabled
<AccessControlProvider storageAdapter={storageAdapter}>
<AppContent />
</AccessControlProvider><AccessGuard permissions={['WRITE_USERS']}>
<button>Add User</button>
</AccessGuard>const { hasPermission } = useAccessControl();
{!hasPermission('WRITE_USERS') && (
<p>You don't have permission to modify users.</p>
)}This example provides a comprehensive overview of how to implement access control in a React application.