How to check permissions on server side
Hello,
I created custom roles and rights and I would like to check permission but if I use
auth.api.hasPermission
, i cannot use project:["my_right"]
So i tried to use authClient but it doesn't work either.
What should i do ?


17 Replies
What was the full method call you did for server side
Im not sure exactly how sveltekit regarding headers
But have a solid look at the documentation the API page is quite nice
Also, the 'Access Control Usage' section of the Organization plugin's docs has an example that could help https://www.better-auth.com/docs/plugins/organization#usage
With changes from that doc to account for getting headers from the PageServerLoad event :
You should be able to use something similar with your 'makeOrder' action instead of the example's 'create' action.
I cannot make it work
Here is what error I get.


@lonelyplanet @rtmorgan
@roze789 could you provide more details on how you assigned the role and what role you assigned to the user you're authenticating as? thank you
yes, my user has admin role

Your earlier screenshots showed customizations for the existing role 'Admin'. Could you confirm that you merged the roles' permissions set with the default roles as covered in the custom permissions step 2 https://www.better-auth.com/docs/plugins/organization#create-roles ?
It could be that the Admin role statements are not correctly established and evaluated.
I didn't, I created my own roles permissions for each one (organization, members, invitation, project)
What do the member records look like in table 'member'? Is there a valid record for a organization member with role 'admin'?
Yes, i changed both


But what i dont understand is why I created those rights only on the authClient
authClient cannot be called in the server ?
ok I forget to add those roles in auth.ts ...
sorry my bad