Skip to content

Instantly share code, notes, and snippets.

@stalniy
Created July 24, 2017 20:03
Show Gist options
  • Save stalniy/38f923f7aa4597595744a09d0492f846 to your computer and use it in GitHub Desktop.
Save stalniy/38f923f7aa4597595744a09d0492f846 to your computer and use it in GitHub Desktop.
CASL expressjs changed
function defineAbilitiesFor(user) {
const { rules, can } = AbilityBuilder.extract()
if (user) {
can('manage', ['Post', 'Comment'], { author: user._id })
can(['read', 'update'], 'User', { _id: user.id })
} else {
can('read', ['Post', 'Comment'])
can('create', 'User')
}
return new Ability(rules)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment