Coder Social home page Coder Social logo

Comments (6)

stalniy avatar stalniy commented on June 15, 2024

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.

hathinhks avatar hathinhks commented on June 15, 2024

@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.

stalniy avatar stalniy commented on June 15, 2024
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:

  1. There are tests that validate all different cases
  2. 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.

hathinhks avatar hathinhks commented on June 15, 2024

@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.

coolbho3k avatar coolbho3k commented on June 15, 2024

@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.

coolbho3k avatar coolbho3k commented on June 15, 2024

Actually scratch what I just said You may be running into this: #778

from casl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.