Comments (6)
It seems it's not a CASL issue. I've just finished example of CASL + Fastify + Prisma and all was good. Please check it here -> https://github.com/stalniy/casl-examples/tree/master/packages/fastify-prisma-blog
from casl.
@stalniy But the error is from calling method on the casl ability object, so how is that not a CASL issue?
Please help me figure out the root cause of this problem. I don't understand why it requires the third parameter to be a string.
My application is a nestjs project by the way.
from casl.
const aNumber: string = 1; // ts error
Who's that error above? :)
You are asking me to look in your code, understand details and help to solve the issue but I do not provide support services for free. I'm pretty sure this is not casl issue because:
- There are tests that validate all different cases
- I've just finished example which works and has no unexpected behavior. You can check it and understand how your code is different from the example and fix it yourelf
from casl.
@stalniy it'd be easier if the error comes from my code, but it's from the ability.can() method from casl package. As I understand the parameters that ability.can() accepts are defined in within these lines of code, am I correct?
type AppAbility = PureAbility<
[
string,
(
| Subjects<{
User: User
}>
| 'all'
),
],
PrismaQuery
>
const { can, cannot, build } = new AbilityBuilder<AppAbility>(createPrismaAbility)
The first parameters to PureAbility is the type of the action (in this case string) and the accepted subject, and the second is the condition object, which in this case is PrismaQuery. There's not a place that defining a third 'string' type parameter.
My code looks almost identical to the documentation, so that's why I don't understand the reason behind the error.
from casl.
@hathinhks I just figured this out, the error message is rather opaque. The Prisma example is not TypeScript in the docs so it doesn't work as-is. The solution is very simple.
The object passed into subject
needs to be of type User
. You need the as User
as follows:
ability.can(Action.Read, subject('User', { role: UserRole.admin } as User));
from casl.
Actually scratch what I just said You may be running into this: #778
from casl.
Related Issues (20)
- Add Support for Mongoose v8 in @casl/mongoose HOT 3
- @casl/[email protected] npm package is missing content HOT 3
- Error: Hydration failed because the initial UI does not match what was rendered on the server. HOT 2
- [not urgent] CLI Yarn warning: @casl/vue 1.x requests version lower than current 6.5.0 HOT 3
- cannot check ability if rules are loaded from database then we create ability using mongoCreateAbility HOT 9
- Extend Rule Checking Mechanism to Evaluate All Rules
- `rulesToQuery` should be generic over the return type of `RuleToQueryConverter` HOT 3
- Update ability JSON HOT 1
- Unable to import `reactiveAbility` from casl/vue HOT 6
- @casl/ability/extra/package.json contains a typo preventing Jest from resolving the package correctly HOT 1
- casl/mongoose 8.0.0 update, error with missing types HOT 1
- Add rule to eslint that forbids using `dist/` imports HOT 1
- [Documentation] Code examples use deprecated Ability
- Typescript issue with the new ofType of accessibleBy HOT 3
- [Bug] Invalid union type for subject when subjects have different actions HOT 4
- Use ability created by express in Vue3
- Unable to understand the implementation of CASL in nextjs App HOT 3
- bug: subject helper error HOT 2
- How to perform conditions on nested objects? HOT 1
- CASL NestJS integration & CASL TypeORM integration
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from casl.