usePermissions vs useCan
what is the difference between usePermissions vs useCan ?
2 Replies
Hi @koop_g. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
usePermissions
and useCan
hooks in refine serve different purposes in handling authorization and access control. Here's a breakdown of their differences:
1. usePermissions
:
- This hook is part of the authentication system in refine.
- It calls the getPermissions
method from the authProvider
.
- It's used to retrieve the user's permissions or roles.
- Typically used for broader authorization checks, like determining a user's role.
Source
2. useCan
:
- This hook is part of the access control system in refine.
- It calls the can
method from the accessControlProvider
.
- It's used for more granular access control checks, typically for specific resources and actions.
- Returns whether a user can perform a specific action on a specific resource.
Source
Example usage of usePermissions
:
Example usage of useCan
:
In summary, usePermissions
is more about retrieving the user's overall permissions or roles, while useCan
is used for checking specific access rights to resources and actions within your application.
Authorization Guide
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1327562833537400895> Kapa.ai is still learning and improving, please let me know how I did by reacting below.