biospringxyz (89) [Avatar] Offline
#1
When run, the following line in the _header.ejs file

"<% if (currentUser) { %>"

fails with the error message:

"ReferenceError: /Users/me/WebstormProjects/epia_section5p2/views/index.ejs:19

currentUser is not defined"

I noticed that "Listing 5.29, Passing data to views (in router.js)" introduces the "currentUser" as in:

res.locals.currentUser = req.user;

However, at this point in Listing 5.11, the reference to currentUser throws an error.

Message was edited by:
biospringxyz
274561 (1) [Avatar] Offline
#2
I am getting the same errors. Did you ever find a resolution to this?
Evan Hahn (70) [Avatar] Offline
#3
Sorry, totally missed this. Looking at this now...
Evan Hahn (70) [Avatar] Offline
#4
Try adding the contents of Listing 6.29 to routes (right before router.get("/")). Here's Listing 6.29 for your convenience:

router.use(function(req, res, next) {
  res.locals.currentUser = req.user;
  res.locals.errors = req.flash("error");
  res.locals.infos = req.flash("info");
  next();
});


You can find the functional app code in the GitHub repository for the book—I just added this code.

I've updated the chapter to fix this, and you'll be getting an update to the MEAP soon. Thanks for catching this!