0

我有一个导出模块,它获取当前用户的 post_id 和 id 以更新我的数据库中的某些内容。直到现在这对我有用:

//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
}

现在我开始使用 Flash 消息,以防出现问题来提醒用户我会这样使用:

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');
    }
}

所以现在我需要以某种方式传递我的变量并在同一个函数中有 req, res 。我怎样才能正确地做到这一点?

// 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 }
4

0 回答 0