cannot understand the use of checkRolePermission is organization plugin

As title says. As far as I can under stand it check if certain role have some permissions or not. Shouldn't it work as if a user have the role and the permission? if not can someone provide me an example of this function and how it's helpfull?
4 Replies
Kevin
Kevin4mo ago
hasPermissions and checkRolePermissions are basically the same thing, the only difference is hasPermissions gets the roles itself by checking the active org and getting the member from the authenticated user and then checking the role against the permissions. so checkRolePermissions does the same thing but from the client so you have to pass the roles yourself for the check to run.
NakedNinja
NakedNinjaOP4mo ago
To pass the role I have the get member for role which also makes an api call so why not just use hasPermission? That why I ask if there is any example use case of this, So I can better understand.
Kevin
Kevin4mo ago
I think its mainly for UI purposes. For example i have an organization provider that my whole app uses, they need to have a active organization to use it. So on mount i fetch all the main details of the org including the currently authenticated user and there membership for that active org (which includes roles). Throught the ui i can use the checkRolePermissions and pass the roles from context. So basically fetch roles once and use anywhere. Obviously this is all client side so you'll still need the do your checks on the server aswell
NakedNinja
NakedNinjaOP4mo ago
Yes I understand the check should go both ways. I guess I have store the data active member data.

Did you find this page helpful?