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
I'm working on setting up authorization in my TypeScript application using CASLand Prisma. In my setup, I use the detectSubjectType function to specify how to detect the subject type, and I expect each item to have the __typename field.
When I check permissions using the ability, I use the as function to ensure the subject has the __typename field:
constability=createAppAbility(prisma,authenticatedUser);constuserToUpdate={id: "1",name: "Alice"};// Example user objectif(ability.can("update",as("User",userToUpdate))){// Update the user}
However, I'm running into a TypeScript error when using ability.can:
Argument of type '{ id: string; name: string; __typename: "User"; }' is not assignable to parameter of type 'AppSubjects'.
Type '{ id: string; name: string; __typename: "User"; }' is not assignable to type 'ForcedSubject<"User">'.
Property '__caslSubjectType__' is missing in type '{ id: string; name: string; __typename: "User"; }' but required in type 'ForcedSubject<"User">'.ts(2345)
It seems that CASL's ForcedSubject type expects the subject to have a __caslSubjectType__ property. But in my setup, I want to use __typename instead.
My Question:
Is there a way to configure CASL so that it uses __typename for the subject type instead of __caslSubjectType__?
How can I modify my setup so that the TypeScript types align correctly and I can use __typename as the subject type identifier?
Additional Information:
I understand that ForcedSubject is a type used internally by CASL to enforce the presence of the __caslSubjectType__ property for type checking. However, since I'm already using __typename in my detectSubjectType function, I'd like to avoid adding another property to my subjects if possible.
What I've Tried:
Attempted to adjust my types to include __caslSubjectType__, but this feels redundant since __typename is already serving that purpose in my setup.
Any help or guidance would be greatly appreciated!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on setting up authorization in my TypeScript application using CASLand Prisma. In my setup, I use the
detectSubjectTypefunction to specify how to detect the subject type, and I expect each item to have the__typenamefield.Here's the relevant part of my ability setup:
I also have an
asfunction that adds the__typenamefield to a subject:When I check permissions using the ability, I use the
asfunction to ensure the subject has the__typenamefield:However, I'm running into a TypeScript error when using
ability.can:It seems that CASL's
ForcedSubjecttype expects the subject to have a__caslSubjectType__property. But in my setup, I want to use__typenameinstead.My Question:
__typenamefor the subject type instead of__caslSubjectType__?__typenameas the subject type identifier?Additional Information:
I understand that
ForcedSubjectis a type used internally by CASL to enforce the presence of the__caslSubjectType__property for type checking. However, since I'm already using__typenamein mydetectSubjectTypefunction, I'd like to avoid adding another property to my subjects if possible.What I've Tried:
Attempted to adjust my types to include
__caslSubjectType__, but this feels redundant since__typenameis already serving that purpose in my setup.Any help or guidance would be greatly appreciated!
Note: I'm using the following versions:
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions