title: Add Request Variable from Client to NodeJS Server for MiddleWare Router
body: <p>I am trying to use routes to help server pages from a nodejs server based on a user being logged in. I am trying to take the login session details from the client side, and pass them back to the NodeJS server to be used in a middleware function for checking authentication.</p>
  
  <p>How do I go about adding a variable to a request for a NodeJS route from the client side?</p>
  
  <p>middleware.js</p>
  
  <pre><code>function loginRequired(req, res, next) {
    if (!req.user) {
      return res.status(401).render("unauthenticated");
    }
    next();
  }
  module.exports = { loginRequired };
  </code></pre>
  
  <p>server.js</p>
  
  <pre><code>app.use("/dashboard", middleware.loginRequired, mainPage);
  </code></pre>
  
  <p>The desired result would be, user clicks "Login", some variables are sent back, as well as the request to that route, the variables (i.e req.user) are used to check authentication.</p>