title: Express.js : about the behavior of next()
body: <p>I'm learning to create web applications using Express.js.
  In the process, we tried to implement a feature to prevent users from accessing certain pages when they are not logged in.</p>
  <pre><code>//  teamController.redirectView : Redirect the screen according to res.locals.redirect
  app.get('/user/:id/team/member', teamController.showMember, teamController.redirectView)
  </code></pre>
  <pre><code>//  The following is a middleware function written in another file(teamController.js)
  showMember: (req, res, next) =&gt; {
  
    //  I want to set the redirect to the '/login' and skip the following process when no user are logging in.
    if(!res.locals.loggedIn) {
      res.locals.redirect = 'login'
      next()
    }
  
    // access the property that is set only when the user logs in
    let userID = res.locals.currentUser.userID
  
    //  Other processes...
  </code></pre>
  <p>When I accessed the URI when the user was not logged in, I was indeed taken to the login page, but I got the following error in the console.</p>
  <pre><code>TypeError: Cannot read property 'userID' of undefined
      at //  the position of 'let userID...'
  Error occured: TypeError: Cannot read property 'userID' of undefined
      //  Abbreviated below...
  </code></pre>
  <p>Does this mean that excuting next() does not skip the following process, like 'return' does?
  Or is there some fatal error that is causing  this error?
  Can you please help me?</p>
  <p>I could have avoided the error by enclosing all subsequent processes in 'else', but if there is a better way, I would appreciate it if you could tell me that too.</p>