Created
April 10, 2020 12:56
-
-
Save stalniy/9845d3a64982a111057b267455be5a8d to your computer and use it in GitHub Desktop.
CASL 4.0 subject type detection for POJO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defineAbility, subject as an } from '@casl/ability'; | |
const object = { | |
title: 'My article', | |
description: '...', | |
}; | |
ability.can('read', an('Article', object)); | |
// or | |
const article = an.bind(null, 'Article'); | |
ability.can('read', article(object)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment