I have an export module that gets a post_id and id of the current user to update something in my DB. Untill now this worked for me:
//call
const promise = authController.function(req.params.post_id, decoded.id);
promise.then(results => res.json(results));
exports.function = async (post_id, decoded) => {
// doing the thing
}
Now I started using flash messages in case something is wrong to alert the user that I would use like this:
exports.function = async (post_id, decoded) => {
// doing the thing
if (error) {
req.flash("flash", 'Your login has expired.'); // or something like that
return res.redirect('back');
}
}
So now I need to somehow pass my variables and have req, res in the same function. How can I do this properly?
// The best I could come up with?
const promise = authController.function(req.params.post_id, decoded.id);
exports.function = async (req, res, post_id, decoded)
{ // the thing }