How to Replace Dynamic Condition Placeholders (e.g., user.id) in CASL Rules Loaded From the Database? #1078
raffidahmad
started this conversation in
General
Replies: 1 comment
|
Please take a look here -> https://casl.js.org/v6/en/cookbook/roles-with-persisted-permissions |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
have a use case where all permission rules are stored in the database, for example:
{ action: 'READ', subject: 'USER', conditions: { 'id': { $eq: 'user.id' } } }In this rule, "user.id" is meant to be a dynamic placeholder that should be replaced with the currently authenticated userβs actual ID before the rule is evaluated by CASL.
My question is:
What is the recommended way to substitute these dynamic placeholders (e.g., "user.id") with real runtime values before passing the rules to new Ability() or ability.update()?
Should this be handled manually on the backend, or is there a built-in or standardized pattern in CASL for resolving placeholders inside stored rule conditions?
Similar problem: https://stackoverflow.com/questions/78830389/in-casl-for-abac-how-do-you-pass-dynamic-conditions-in-the-json
All reactions