Casl: Object prototype may only be an Object or null: undefined on no abiltity

Created on 10 Apr 2020  路  2Comments  路  Source: stalniy/casl

I am trying to use the accessibleBy function from @casl/mongoose like this:

const matchesAbilityRights = await database
      .model("Person")
      .accessibleBy(user.ability);

My ability is defined from this JSON array:

[
  {
    action: 'read',
    subject: 'User',
    conditions: { 'organizations.organization': 5e318fb83002794738039ae2 }
  },
  { action: 'create', subject: 'User' },
  {
    subject: 'Person',
    action: 'delete',
    conditions: { creator: { '$in': [ 5d51518e5b84777cd6f54bcb ] } }
  }
]

This error is thrown when you don't have the ability. But when you do, it works like expected.

TypeError: Object prototype may only be an Object or null: undefined
    at Function.create (<anonymous>)
    at /Users/data-api/node_modules/@casl/mongoose/dist/umd/index.js:1:852
    at Function.u [as accessibleBy] (/Users/data-api/node_modules/@casl/mongoose/dist/umd/index.js:1:969)
    at /Users/data-api/dist/api/person/person.js:33:18
    at Generator.next (<anonymous>)
    at /Users/data-api/dist/api/person/person.js:8:71
bug

All 2 comments

Hi

Thanks for the time to contribute this issue! The issue is fixed now and I'm currently working on another issue with types. When that is finished, I will release a patch version.

Plan to be done today, probably tomorrow

fixed in @casl/[email protected]. Thanks again!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nidkil picture nidkil  路  5Comments

ivanwitzke picture ivanwitzke  路  3Comments

LyhjeHylje picture LyhjeHylje  路  5Comments

m-weeks picture m-weeks  路  5Comments

Foxh0und picture Foxh0und  路  3Comments