The middleware function below can't access req.user or check is the user is logged in after the user logs in.

I know that passport.serializeUser is succeeding after the log in and that req is defined at the time it is accessed from the middleware function.

I am new to node and its packages, so I might be missing something basic. Any help is greatly appreciated.

Middleware function:

app.use('/private/*', function(req, res, next) { console.log(req.user); // returns undefined console.log(req.isAuthenticated()) // returns false res.redirect('/') });

Full Code: