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
import{createMongoAbility,ForcedSubject,CreateAbility,MongoAbility,AbilityBuilder}from'@casl/ability'import{MedusaError}from'@medusajs/framework/utils'import{MemberDTO,MemberRole}from'src/modules/seller/types'exportconstactions=['manage','read','create','update','delete']asconstexportconstsubjects=['Invite','Member','Seller','Product','all']asconsttypeAppAbilities=[(typeofactions)[number],(|(typeofsubjects)[number]|ForcedSubject<Exclude<(typeofsubjects)[number],'all'>>)]exporttypeAppAbility=MongoAbility<AppAbilities>exportconstcreateAppAbility=createMongoAbilityasCreateAbility<AppAbility>typeDefinePermissions=(member: MemberDTO,builder: AbilityBuilder<AppAbility>)=>voidtypeRoles=MemberRoleconstrolePermissions: Record<Roles,DefinePermissions>={[MemberRole.OWNER]: (member,{ can })=>{can('manage','all')},[MemberRole.ADMIN]: (member,{ can })=>{can('manage','all')},[MemberRole.MODERATOR]: (member,{ can })=>{can('read','Product')can('read','Invite')can('read','Seller')can('read','Member')can('update','Member',{id: member.id})}}exportfunctiondefineAbilityFor(member: MemberDTO){constbuilder=newAbilityBuilder(createAppAbility)if(typeofrolePermissions[member.role]==='function'){rolePermissions[member.role](member,builder)}else{thrownewMedusaError(MedusaError.Types.UNEXPECTED_STATE,`Trying to use unknown role "${member.role}"`)}returnbuilder.build()}
But I get this typescript error that I can not pass id in here
can('update','Member',{id: member.id})
Changing syntax to mongo query does not help.
Expected behavior
I should not get any typescript error
The text was updated successfully, but these errors were encountered:
Describe the bug
I'm using this guide to setup rbac in my application https://casl.js.org/v6/en/cookbook/roles-with-static-permissions.
Here is my final code:
But I get this typescript error that I can not pass id in here
Changing syntax to mongo query does not help.
Expected behavior
I should not get any typescript error
The text was updated successfully, but these errors were encountered: