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
Make sure you [enable auth features](https://marmelab.com/react-admin/Authentication.html#enabling-auth-features) by setting an `<Admin authProvider>`, and [disable anonymous access](https://marmelab.com/react-admin/Authentication.html#disabling-anonymous-access) by adding the `<Admin requireAuth>` prop. This will ensure that react-admin waits for the `authProvider` response before rendering anything.
72
+
71
73
**Tip**: ra-rbac is part of the [React-Admin Enterprise Edition](https://marmelab.com/ra-enterprise/), and hosted in a private npm registry. You need to subscribe to one of the Enterprise Edition plans to access this package.
72
74
73
75
## Concepts
@@ -141,6 +143,10 @@ const corrector123Role = [
141
143
];
142
144
```
143
145
146
+
**Tip**: The _order_ of permissions isn't significant. As soon as at least one permission grants access to an action on a resource, ra-rbac grant access to it - unless there is an [explicit deny](#explicit-deny).
147
+
148
+
The RBAC system relies on *permissions* only. It's the `authProvider`'s responsibility to map roles to permissions. See the [`authProvider` Methods](#authprovider-methods) section for details.
149
+
144
150
### Record-Level Permissions
145
151
146
152
By default, a permission applies to all records of a resource.
@@ -182,7 +188,7 @@ const allProductsButStock = [
182
188
183
189
## `authProvider` Methods
184
190
185
-
Ra-rbac builds up on react-admin's `authProvider` API. It precises the return format of the `getPermissions()` method which must return a promise for object containing `permissions` (an array of permissions).
191
+
Ra-rbac builds up on react-admin's `authProvider` API. It precises the return format of the `getPermissions()` method which must return a promise for an array of permissions objects.
186
192
187
193
```jsx
188
194
constauthProvider= {
@@ -193,17 +199,27 @@ const authProvider = {
193
199
};
194
200
```
195
201
196
-
For every restricted resource, ra-rbac calls `authProvider.getPermissions()` to get the permissions.
202
+
For every restricted resource, ra-rbac calls `authProvider.getPermissions()` to get the permissions. In practice, the permissions are usually returned upon login rather than in the `authProvider` code. The authProvider stores the permissions in memory or localStorage.
197
203
198
-
For the example dataProvider above, this translates to the following set of permissions:
204
+
`authProvider.getPermissions()` doesn't return roles - only permissions. Usually, the role definitions are committed with the application code, as a constant. The roles of the current user are fetched at login, and the permissions are computed from the roles and the role definitions.
You can use the `getPermissionsFromRoles` helper in the `authProvider` to compute the permissions that the user has based on their permissions. This function takes an object as argument with the following fields:
201
207
202
-
In practice, the permissions are usually returned upon login rather than in the `authProvider` code. The authProvider stores the permissions in memory or localStorage. The `authProvider.getPermissions()` method only retrieve the permissions from localStorage.
208
+
-`roleDefinitions`: a static object containing the role definitions for each role
209
+
-`userRoles`_(optional)_: an array of roles (admin, reader...) for the current user
210
+
-`userPermissions`_(optional)_: an array of permissions for the current user, to be added to the permissions computed from the roles
203
211
204
-
```jsx
212
+
Here is an example `authProvider` implementation following this pattern:
0 commit comments