getjerry / nest-casl

Casl integration for NestJS
MIT License
216 stars 29 forks source link

Cannot read properties of undefined (reading 'everyone') #670

Open shankiflang opened 1 year ago

shankiflang commented 1 year ago

Hi, I'm looking to use nest with casl (hence the use of this lib). I'm using prisma for the data part (which isn't native to nest-casl, so can cause problems). Here is the definition of my permissions: image

And this is the error I receive: image

MarioZ2002 commented 1 year ago

@shankiflang Did you find the problem? I have a imilar issue.

shankiflang commented 1 year ago

@shankiflang Did you find the problem? I have a imilar issue.

no! I ended up using casl without nest-casl by configuring my own permissions and this works.

falyoun commented 1 year ago

Same here

Seesaem commented 1 year ago

Have you correctly imported the module features in your module?

@Module({
  imports: [CaslModule.forFeature({ permissions })],
})

I had the same issue while testing and it was this missing import inside my beforeEach that triggered this error

vadimpan4uk commented 9 months ago

it works, but in a specific way.

CaslModule.forRoot<Roles>({
      // Role to grant full access, optional
      superuserRole: Roles.admin,
      // Function to get casl user from request
      // Optional, defaults to `(request) => request.user`
      getUserFromRequest: (request) => request.currentUser,
    }),

must be in AppModule and

@Module({
  imports: [CaslModule.forFeature({ permissions })],
})

must be in the other one. and controller where you are going to use it must be in the same module where you declared CaslModule.forFeature({ permissions })

mareksuscak commented 6 months ago

I'm running into this issue as well and it seems that everything works as expected when I import the CaslModule in the same module where I import permissions but when I encapsulate the configuration in another module, re-export the CaslModule and then import the parent module into the feature module, that's when I get this error. Hope it makes sense.

mareksuscak commented 5 months ago

I think this is related to https://github.com/getjerry/nest-casl/issues/905 and I think the line of code that is commented out and is being mentioned in the other ticket is the reason this is happening as well.