change AbilityBuilder on state update
See original GitHub issueI have below code in ability.js
// Defines how to detect object's type
function subjectName(item) {
if (!item || typeof item === 'string') {
return item;
}
return item.__type;
}
let state = null;
store.subscribe(() => {state = store.getState()});
export default AbilityBuilder.define({subjectName}, can => {
can('delete', 'Post', {userId: state.auth.userId});
});
and i use redux and react-redux for handling my state in react app
my question is, how can i update my AbilityBuilder when my app’s state updated?
because my userId
come from state.
thanks 😃
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Define Rules - CASL
There are 3 ways you can define abilities: using defineAbility function; using AbilityBuilder class; using JSON objects. In order to understand which way...
Read more >stalniy-casl/casl - Gitter
Retrieve ids of all vehicles when you define rules. This works good in case if amount of vehicles not big (<= 1000). const...
Read more >Casl Vue set ability on reload + in router + after login based on ...
The issue is that if you pass async function inside AbilityBuilder.define then AbilityBuilder.define returns a Promise .
Read more >How to manage dynamic permissions using CASL & Redux
Here we are importing Ability and AbilityBuilder from @casl/ability . ... const authReducer = (state = INITIAL_STATE, action) => {. 4. switch (action.type) ......
Read more >React, Manage Dynamic Permissions Using CASL & Redux.
import { Ability, AbilityBuilder } from "@casl/ability"; const ability ... const authReducer = (state = INITIAL_STATE, action) => { switch ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
i do exactly the same to you but i cant update ability . please tell me why ??? when i logout and login to another user, the ability didn’t update.
Hi,
You don’t need to update
AbilityBuilder
. It’s just a helper class. What you want to do is to update rules in yourAbility
instance.So, the approximate code should be something like this: