You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/IfCanAccess.md
+85-3Lines changed: 85 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,10 @@ title: "IfCanAccess"
7
7
8
8
This component, part of [the ra-rbac module](https://marmelab.com/ra-enterprise/modules/ra-rbac#ifcanaccess)<imgclass="icon"src="./img/premium.svg" />, relies on the `authProvider` to render its child only if the user has the right permissions. It accepts the following props:
9
9
10
-
-`action` (string, required): the action to check, e.g. 'read', 'list', 'export', 'delete', etc.
11
-
-`resource` (string, optional): the resource to check, e.g. 'users', 'comments', 'posts', etc. Defaults to the current resource.
12
-
-`record` (object, optional): the record to check. If passed, the child only renders if the user has permissions for that record, e.g. `{ id: 123, firstName: "John", lastName: "Doe" }`
10
+
-`action` (`string`, required): the action to check, e.g. 'read', 'list', 'export', 'delete', etc.
11
+
-`resource` (`string`, optional): the resource to check, e.g. 'users', 'comments', 'posts', etc. Falls back to the current resource context if absent.
12
+
-`record` (`object`, optional): the record to check. If passed, the child only renders if the user has permissions for that record, e.g. `{ id: 123, firstName: "John", lastName: "Doe" }`
13
+
-`fallback` (`ReactNode`, optional): The element to render when the user does not have the permission. Defaults to `null`.
13
14
14
15
Additional props are passed down to the child element.
15
16
@@ -31,3 +32,84 @@ const RecordToolbar = () => (
31
32
</Toolbar>
32
33
);
33
34
```
35
+
36
+
## Showing An Access Denied Message Instead Of A Not Found Page
37
+
38
+
`ra-rbac` shows a Not Found page when users try to access a page they don't have the permissions for. It is considered good security practice not to disclose to a potentially malicious user that a page exists if they are not allowed to see it.
39
+
40
+
However, should you prefer to show an Access Denied screen in those cases, you can do so by using the `Resource` component from `react-admin` instead of the one from `ra-rbac` and leveraging the `IfCanAccess` component in your views:
Copy file name to clipboardExpand all lines: docs/canAccess.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,4 +68,44 @@ const ProductList = () => {
68
68
69
69
**Tip**: Ra-rbac actually proposes a `<Datagrid>` component that hides columns depending on permissions. Check [the RBAC documentation](./AuthRBAC.md) for details.
70
70
71
+
You don't have to provide an `action` if you just want to know whether users can access any screen of the resource. This is useful to leverage `canAccess` in an `<Admin>` component children function:
In this example, users will see the products list and will be able to click on its category link to edit the category. However, they won't see the categories list nor the commands list.
110
+
71
111
**Tip**: Instead of calling `usePermissions` and `canAccess`, you can call [the `useCanAccess` hook](./useCanAccess.md).
0 commit comments