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
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
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
Function isLoggedIn (req, res, next) {
If (req.isAuthenticated ()) Return next ();
Res.redirect ('/login'); }
Try using return res.redirect
instead of res.redirect
and tell me what happens. (same for render)
Also, what does the console.log(req.session)
give you ?
在护照中,有一个内置函数,req.isAuthenticated()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.