Skip to content

Instantly share code, notes, and snippets.

@stalniy
Created July 26, 2017 12:03
Show Gist options
  • Save stalniy/d95585182bcb652cfa4b58e947637dbf to your computer and use it in GitHub Desktop.
Save stalniy/d95585182bcb652cfa4b58e947637dbf to your computer and use it in GitHub Desktop.
CASL blog app abilities ES6
import { AbilityBuilder } from 'casl'
const user = whateverLogicToGetUser()
const ability = AbilityBuidler.define(can => {
can('read', ['Post', 'Comment'])
if (user.isLoggedIn) {
can('create', 'Post')
can('manage', ['Post', 'Comment'], { authorId: user.id })
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment