【发布时间】:2015-01-30 00:31:50
【问题描述】:
我正在尝试学习 Express 会话和身份验证处理。
例如:
app.post('/login', authCredentials, function(req, res) {
console.log("second")
});
function authCredentials(req, res, next) {
//this happens first
console.log(req.body) // => { username: etc, password: etc }
next();
}
我的问题是我的authCredentials 函数应该做多少?
例如,如果凭据正确,我可以执行类似的操作
res.redirect('/index')。但是,一旦我这样做了,第二个功能有什么目的?
其他问题:
- 如何处理无效凭据?
- 如果我让
authCredentials只是根据凭据返回true或false,这不会破坏中间件流程,因为它永远不会调用next()? - 是否可以在之后的匿名回调中访问
authCredentials中的任何内容?基本上在function(req, res) { }?
【问题讨论】:
标签: javascript express middleware