_req_user is undefined on pre/post remove hooks
See original GitHub issueThe following middlewares output an undefined _req_user
:
Article.schema.pre('remove', function reqUserDebug (next) {
console.log('================ pre remove _req_user ================')
console.log(this._req_user);
return next();
});
Article.schema.post('remove', function reqUserDebug (next) {
console.log('================ post remove _req_user ================')
console.log(this._req_user);
return next();
});
output:
================ pre remove hook _req_user ================
undefined
================ post remove hook _req_user ================
undefined
I do not know if it is useful but here is some background about my project regarding this issue:
I am developing a website with some role limitation on the back-office. I am using the _req_user
on pre save hook to limit modifications. But without the _req_user
on pre remove hook it is impossible to limit the remove rights.
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Why does .pre find query return undefined in this case?
I just learnt about pre/post hooks and I wanted to test it. When I try to console.log it (so I can see it...
Read more >'this' keyword is equivalent to 'undefined' · Issue #1518 - GitHub
It comes from this part of the code: babelHelpers; var _this = undefined; const prepost = () => fn => (() => {...
Read more >Extending Schemas — marshmallow 3.19.0 documentation
One common use case is to wrap data in a namespace upon serialization and unwrap the data during deserialization. from marshmallow import Schema, ......
Read more >LS-DYNA Version 970 Keyword User's Manual
An option to add or remove discrete beams during a calculation is available with the new keyword: *PART_SENSOR. • Multiple jetting is now...
Read more >All other San Diego fixes - Product Documentation | ServiceNow
Removed features and products in San Diego ... For the Submit Catalog Item Request action, the default variable value doesn't apply.
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
Was there actually a solution for this? Sorry just looked around and all issues are closed but I still have this issue.
If you use update scripts, leveraging the updatedBy field will not work (it is unset in the context of an update script). I am now using @poksme 's solution.