req.user
not accessible anywhere except its origin function.
I read that passport attaches the user to every request after authentication.
I want to stop any user from accessing the inner pages through the url bar thus skipping the login page or if his session is already active he must be redirected to the user page. These two things can be done only if I get access to req.user
in all the middlewares.
app.js:-
app.post('/',passport.authenticate('local',{failureRedirect: '/'}),
function(req,res,next){
console.log(req.user); //req.user defined here only not in users.js
res.redirect('/users');
});
users.js:-
router.get('/users', function(req, res, next) {
console.log(req.user);//undefined
res.render('users');
});
DeserializeUser:-
passport.deserializeUser(function(id, done) {
db.findById(id, function(err, user) {
done(err, user);
console.log(user) //undefined
});
});