I have a middleware that is being called upon a route.
router.get('/:endpoint', authController.isLoggedIn, userController.getPages);
I need to check if the user isLogged and then call getPages from the userController.
but the isLogged middleware is not doing anything...
exports.isLoggedIn = (req, res, next) => {
// first check if the user is authenticated
console.log(res.locals.user)
if (true) {
console.log(res.locals.user)
next(); // carry on! They are logged in!
return;
}
};
It should show on the console the value of res.locals.user or undefined, but it doesnt.
Has anyone any idea why is that?
That was a very stupid mistake I made.
At the very end of my authController.js file I had another definition of isLoggedIn
so as I removed that and left just the one I needed, everything worked as it should.
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.