biospringxyz (89) [Avatar] Offline
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:
274561 (1) [Avatar] Offline
I am getting the same errors. Did you ever find a resolution to this?
Evan Hahn (70) [Avatar] Offline
Sorry, totally missed this. Looking at this now...
Evan Hahn (70) [Avatar] Offline
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");

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!