Replies: 2 comments 2 replies
|
@KATT @d-tw I'm not familiar with Prisma, but wouldn't you just do the check on the ability before the create on the data itself: async function createPost(data: PostUncheckedCreateInput, prisma, user) {
const ability = getAbility(user);
if(!ability.can("write", "Post", data)) throw new Error("Not Authorized!");
return await prisma.post.create({
data,
})
} |
2 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.
Hey!
I've just started playing around with CASL and using the Prisma-adapter I have a pretty basic use-case question that I'm surprised that I can't find the answer to, so it must be me being silly.
What is unclear to me right now, is how to handle restricted events on writes. On read it's pretty straight-forward to spread the
accessibleBy(ability, 'read').Attachmentor similar.Given a a project with an ability that looks something like this:
How can I restrict this function that creates a
Postto make sure they only can createPosts within their own organization?Really appreciate the help. CASL looks awesome.
All reactions