Skip to main content
Version: Next

Permissions

ABP React provides fine-grained permission checking for access control.

usePermission Hook

The usePermission hook provides permission checking utilities:

import { usePermission } from '@abpjs/core';

function PermissionExample() {
const { hasPermission, hasAnyPermission, hasAllPermissions } = usePermission();

return (
<div>
{hasPermission('AbpIdentity.Users') && (
<a href="/users">Manage Users</a>
)}

{hasPermission('AbpIdentity.Roles') && (
<a href="/roles">Manage Roles</a>
)}

{hasPermission('AbpIdentity.Users.Create') && (
<button>Create User</button>
)}
</div>
);
}

API Reference

usePermission Returns

MethodTypeDescription
hasPermission(permission: string) => booleanCheck if user has a specific permission
hasAnyPermission(permissions: string[]) => booleanCheck if user has any of the permissions
hasAllPermissions(permissions: string[]) => booleanCheck if user has all permissions

Common ABP Permissions

Identity Permissions

PermissionDescription
AbpIdentity.UsersView users
AbpIdentity.Users.CreateCreate users
AbpIdentity.Users.UpdateUpdate users
AbpIdentity.Users.DeleteDelete users
AbpIdentity.Users.ManagePermissionsManage user permissions
AbpIdentity.RolesView roles
AbpIdentity.Roles.CreateCreate roles
AbpIdentity.Roles.UpdateUpdate roles
AbpIdentity.Roles.DeleteDelete roles
AbpIdentity.Roles.ManagePermissionsManage role permissions

Tenant Management Permissions

PermissionDescription
AbpTenantManagement.TenantsView tenants
AbpTenantManagement.Tenants.CreateCreate tenants
AbpTenantManagement.Tenants.UpdateUpdate tenants
AbpTenantManagement.Tenants.DeleteDelete tenants
AbpTenantManagement.Tenants.ManageFeaturesManage tenant features

Checking Multiple Permissions

import { usePermission } from '@abpjs/core';

function AdminPanel() {
const { hasAnyPermission, hasAllPermissions } = usePermission();

// Show if user can manage either users OR roles
const canManageIdentity = hasAnyPermission([
'AbpIdentity.Users',
'AbpIdentity.Roles',
]);

// Show only if user can manage BOTH users AND roles
const isFullAdmin = hasAllPermissions([
'AbpIdentity.Users',
'AbpIdentity.Roles',
'AbpIdentity.Users.ManagePermissions',
]);

return (
<div>
{canManageIdentity && <a href="/identity">Identity Management</a>}
{isFullAdmin && <a href="/admin">Full Admin Panel</a>}
</div>
);
}

Permission-Based Rendering

Create a reusable component for permission-based rendering:

import { usePermission } from '@abpjs/core';

interface PermissionGuardProps {
permission: string | string[];
requireAll?: boolean;
children: React.ReactNode;
fallback?: React.ReactNode;
}

function PermissionGuard({
permission,
requireAll = false,
children,
fallback = null,
}: PermissionGuardProps) {
const { hasPermission, hasAnyPermission, hasAllPermissions } = usePermission();

let hasAccess = false;

if (typeof permission === 'string') {
hasAccess = hasPermission(permission);
} else if (requireAll) {
hasAccess = hasAllPermissions(permission);
} else {
hasAccess = hasAnyPermission(permission);
}

return hasAccess ? <>{children}</> : <>{fallback}</>;
}

// Usage
<PermissionGuard permission="AbpIdentity.Users.Create">
<button>Create User</button>
</PermissionGuard>