-
Hey there! I'm switching my app from a home-made permission system to casl. Although it's been a rough start, I'm starting to enjoy its simplicity more and more! Anyway I'm checking permissions in a service like so: const ability = this.caslAbilityFactory.createForUser(user);
if (ability.cannot(Action.Update, post)) // post is an entity fetched from the DB, not the subject's base class)
throw new ForbiddenException('Update not permitted'); // Coming from Nest.js But I'd like to send the exact reason why it was denied (the reason specified in I could get .relevantRuleFor and do the check myself but this feels extremely hackish... Thanks! EDIT: I forgot to mention, I've tried to use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can use If this doesn’t work for you, then you need to use |
Beta Was this translation helpful? Give feedback.
You can use
ForbiddenError.from(ability).throwUnlessCan(...)
and it will throw an instance ofForbiddenError
which has message of the reason.If this doesn’t work for you, then you need to use
relevantRuleFor(...)