i just started working on Passport local and i am new to it so here's the problem When I Console.log() after Authentication successfully, Session is there,
app.use('/login',
passport.authenticate('local', { failureRedirect: '/' }),
function(req, res) {
console.log(req.session);
res.redirect('/home');
});
Output Of Console.Log
Session {
cookie:
{ path: '/',
_expires: 2017-08-03T19:42:58.728Z,
originalMaxAge: 14400000,
httpOnly: true,
secure: false },
passport: { user: '5909a6c0' } }
But when i console.log in /Home page or Using this function in App.js It is Undefined, session is not saved.
function isLoggedIn(req, res, next) {
console.log(req.user);
if (req.user)
return next();
else
return res.status(401).json({
error: 'User not authenticated'
})
}
Output of Console.log now,
Session {
cookie:
{ path: '/',
_expires: 2017-05-08T19:43:10.503Z,
originalMaxAge: 14400000,
httpOnly: true,
secure: false } }
I Appreciate Your help
via Krunal Limbad
No comments:
Post a Comment