So I'm trying to render the user's name on the navbar. So far I have a routes folder, views folder and a partial folder. When I try to render the user's name on the profile page and the homepage it works.This is it:router.get('/', (req, res) => { res.render('index', { title: 'Site', name: req.user.username, // <-- Line 10 image: req.user.image, }); }); // @desc Profile // @route GET/profile router.get('/profile', (req, res) => { res.render('profile', { name: req.user.username, title: req.user.username, image: req.user.image, }); }); However, when I go to /logout, I get:TypeError: Cannot read property 'username' of undefined at C:\Users\Desktop\Code\site\routes\index.js:10:20 if I remove line 10 and 11 and I try to log out it works fine. I though this may be a problem because _nav is a partial but then why am I getting an error only when I use it on '/'.Thanks!
Submitted September 04, 2020 at 03:25AM by PhoenixBeatsYT
No comments:
Post a Comment