Replies: 2 comments
-
Hi @KATT - did you ever find a solution for this? |
Beta Was this translation helpful? Give feedback.
0 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,
})
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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').Attachment
or similar.Given a a project with an ability that looks something like this:
How can I restrict this function that creates a
Post
to make sure they only can createPost
s within their own organization?Really appreciate the help. CASL looks awesome.
Beta Was this translation helpful? Give feedback.
All reactions