[英]Page is not properly redirecting with express-session and passport nodejs
I am using passport-local and express-session but my problem is that when I enter an address, after I close the session, I get the problem the browser "Page is not properly redirecting", so what I want to do is redirect to The address / login instead of showing that problem我正在使用本地护照和快速会话,但我的问题是当我输入地址时,关闭会话后,我遇到浏览器“页面未正确重定向”的问题,所以我想做的是重定向到地址/登录名而不是显示该问题
I'll leave my code我会留下我的代码
Routes.js路由.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
});
}
});
app.js应用程序.js
app.use(session({
secret : 'asjdknas',
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
update solved更新解决了
The verification I did the function I was calling in app.get call验证我做了我在 app.get call 中调用的函数
Function isLoggedIn (req, res, next) {函数 isLoggedIn (req, res, next) {
If (req.isAuthenticated ()) Return next (); if (req.isAuthenticated()) 返回 next();
Res.redirect ('/login'); Res.redirect('/登录'); }
}
Try using return res.redirect
instead of res.redirect
and tell me what happens.尝试使用
return res.redirect
而不是res.redirect
并告诉我会发生什么。 (same for render) (渲染相同)
Also, what does the console.log(req.session)
give you ?另外,
console.log(req.session)
给你什么?
在护照中,有一个内置函数,req.isAuthenticated()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.