You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package is a bit different from all others because it provides a custom `PrismaAbility` class that is configured to check permissions using Prisma [WhereInput](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#where):
24
+
This package is a bit different from all others because it provides a custom `createPrismaAbility` factory function that is configured to check permissions using Prisma [WhereInput](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#where):
25
25
26
26
```ts
27
27
import { User, Post, Prisma } from'@prisma/client';
That function accepts `PrismaAbility` instance and `action` (defaults to `read`), returns an object with keys that corresponds to Prisma model names and values being aggregated from permission rules `WhereInput` objects.
76
+
That function accepts `Ability` instance and `action` (defaults to `read`), returns an object with keys that corresponds to Prisma model names and values being aggregated from permission rules `WhereInput` objects.
78
77
79
78
**Important**: in case user doesn't have ability to access any posts, `accessibleBy` throws `ForbiddenError`, so be ready to catch it!
80
79
@@ -128,6 +127,16 @@ type AppSubjects = Subjects<{
128
127
}>; // 'User' | Model<User, 'User'>
129
128
```
130
129
130
+
To support rule definition for `all`, we just need to explicitly do it:
Prisma allows [to generate client into a custom directory](https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-client#using-a-custom-output-path) in this case `@prisma/client` doesn't re-export needed types anymore and `@casl/prisma` cannot automatically detect and infer types. In this case, we need to provide required types manually. Let's assume that we have the next configuration:
0 commit comments