My navigation bar is set up to show the following on the right side of the screen:
Welcome, <%= user %>
The issue is that I can only access the user
data if I render it in the following way:
router.get("/", function (req, res, next) {
const user = req.user.username;
res.render("index", user);
});
The problem arises when I'm not logged in, preventing the webpage from loading and showing an undefined error:
TypeError: Cannot read properties of undefined (reading 'username')
. Is there a solution to adding a default value for user
or displaying a Sign Up button instead to prevent this TypeError?