[英]Authentication with NodeJS, Express-Session and Passport fails
[英]Page is not properly redirecting with express-session and passport nodejs
我正在使用本地护照和快速会话,但我的问题是当我输入地址时,关闭会话后,我遇到浏览器“页面未正确重定向”的问题,所以我想做的是重定向到地址/登录名而不是显示该问题
我会留下我的代码
路由.js
app.get('/index', isLoggedIn, function(req, res) {
console.log(req.session);
if (req.session == null || req.session == undefined)
{
res.redirect('/login');
}
else
{
res.render('index.ejs', {
user : req.user // get the user out of session and pass to template
});
}
});
应用程序.js
app.use(session({
secret : 'asjdknas',
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
更新解决了
验证我做了我在 app.get call 中调用的函数
函数 isLoggedIn (req, res, next) {
if (req.isAuthenticated()) 返回 next();
Res.redirect('/登录'); }
尝试使用return res.redirect
而不是res.redirect
并告诉我会发生什么。 (渲染相同)
另外, console.log(req.session)
给你什么?
在护照中,有一个内置函数,req.isAuthenticated()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.