mongoose `.orFail()` does not work when permissions are implicitly denied
See original GitHub issueI ran into this issue accidentally today, but the way my application is set up, it expends models not found to throw an error.
ex:
var user = await User.findById(req.params.id)
.accessibleBy(req.ability)
.orFail();
res.json({ user });
When the permission to view users is set, it works fine and dandy. The conditions for this query were { _id: '5d600d0ea21964033b4fc1bb', '$and': [ {} ] }
.
But if the permission is implicitly denied, the conditions are { _id: '5d600d0ea21964033b4fc1bb', __forbiddenByCasl__: 1 }
. The problem is though that the user
variable is returning null, and not throwing an exception.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Express Handlebars denied access to mongoose object
One solution may be to put a .lean() on my mongoose methods. There must be a cleaner way. Any ideas of a resolution...
Read more >mongoose | Yarn - Package Manager
Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports Node.js and Deno (alpha).
Read more >Mongoose v6.8.2: API docs
Used for declaring paths in your schema that should be 128-bit decimal floating points. Do not use this to create a new Decimal128...
Read more >Access is denied. : Permission denied Reason: 13 - MongoDB
Open a Command Prompt with Administrative privileges. Ctrl + Shift + Click on Control Prompt. Run (The path to mongo executables is enter...
Read more >Express Tutorial Part 3: Using a Database (with Mongoose)
Note: You don't need to know MongoDB in order to use Mongoose, ... results==null ) or daisy chain the orFail() method on the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fixed in
@casl/mongoose@2.3.2
.Thanks for the issue!
Thanks, I didn’t know about
orFail
method of mongooseQuery
😃I think this is a bug but I’ll need some time to confirm this.