Express passport ldap nodejs如何将变量传递给另一个中间件
你好,你能帮我吗 在app.js上,我使用passport ldapauth startegy和works 。。。。在执行成功重定向之前,我需要查询表mysql并检查用户的授权 我想我做到了,我成功地重定向到索引,我有一个导出模块调用accessoSicuro:Express passport ldap nodejs如何将变量传递给另一个中间件,express,passport.js,Express,Passport.js,你好,你能帮我吗 在app.js上,我使用passport ldapauth startegy和works 。。。。在执行成功重定向之前,我需要查询表mysql并检查用户的授权 我想我做到了,我成功地重定向到索引,我有一个导出模块调用accessoSicuro: // accessSicuro It's exported module: module.exports = { accessoSicuro:function(req,res,next){ if(req.isAuthentic
// accessSicuro It's exported module:
module.exports = {
accessoSicuro:function(req,res,next){
if(req.isAuthenticated()){
/*
HERE I WANT to check the mysql table and pass the returned parameter to next () method and then use the value to the middleware index
*/
return next();
}
req.flash('msg_errore','Sorry, no entry, no auth ldap');
res.redirect('/login');
}
}
app.get('/index',accessoSicuro,(req,res,next)=>{
// HERE THE RESPONSE VALUE OF mysql response FROM accessoSicuro method
sess=req.session;
idUser = sess.passport.user;
res.render('index');
});
非常感谢我认为您无法通过next()中间件传递变量。最佳实践(因为它是express文档中提到的)是使用实际上
res。局部变量
仍然通过res
变量传递给next()
。中间件中的next
函数允许您传递1个参数。在这种情况下,express将使用(err,req,res,next)
参数查找第一个中间件。在本例中,您传递的参数是err
(即next(err)
)。
// accessSicuro It's exported module:
module.exports = {
accessoSicuro:function(req,res,next){
if(req.isAuthenticated()){
/*
HERE I WANT to check the mysql table and pass the returned parameter to next () method and then use the value to the middleware index
*/
return next();
}
req.flash('msg_errore','Sorry, no entry, no auth ldap');
res.redirect('/login');
}
}
app.get('/index',accessoSicuro,(req,res,next)=>{
// HERE THE RESPONSE VALUE OF mysql response FROM accessoSicuro method
sess=req.session;
idUser = sess.passport.user;
res.render('index');
});