question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

_req_user is undefined on pre/post remove hooks

See original GitHub issue

The 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:closed
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Nefil33commented, Feb 14, 2017

Was there actually a solution for this? Sorry just looked around and all issues are closed but I still have this issue.

1reaction
r1bcommented, Apr 5, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found