React hooks for authorization in zopio
applications
@repo/auth-hooks
package provides React hooks for authorization in zopio
applications. It works in conjunction with the authorization runner to provide a seamless way to check user permissions in React components.
useAccess
, which allows you to check if a user has permission to perform a specific action on a resource.
Property | Type | Description | Required |
---|---|---|---|
resource | string | The resource being accessed (e.g., ‘posts’, ‘users’) | Yes |
action | string | The action being performed (e.g., ‘create’, ‘read’, ‘update’, ‘delete’) | Yes |
field | string | Optional field within the resource | No |
record | any | The record data being accessed | No |
context | any | Context information for evaluation (e.g., current user, roles) | Yes |
Property | Type | Description |
---|---|---|
can | boolean | Indicates if access is allowed |
reason | string | Optional explanation for the access decision |
loading | boolean | Indicates if the access check is in progress |
useAccess
hook internally uses the evaluateAccess
function from the @repo/auth-runner
package to perform the actual permission check. This ensures consistency between your React components and other parts of your application.