title: How do I pass authentication tokens/headers?
body: <p>I have designed an authentication function that works perfectly when tested via my POSTMAN endpoint. This is what it looks like when the <strong>Authorization</strong> value is correct: <a href="https://i.stack.imgur.com/OsQ6Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OsQ6Y.png" alt="successful authorization" /></a></p>
  <p>And this is what it looks like when I alter the <strong>Authorization</strong> value to deliberately fail the authorization process:</p>
  <p><a href="https://i.stack.imgur.com/xyciR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xyciR.png" alt="failed authorization" /></a></p>
  <p>Find below the authorization code:</p>
  <pre><code>const jwt = require ('jsonwebtoken');
  const authenticate = (req, res, next)=&gt;{
      try {
          const token = req.headers.authorization.split(' ')[1]
          const decode = jwt.verify(token, 'verySecretValue')
          console.log('Authentication PASSED!');
          next();
          
      }
      catch (error) {
          
          res.json({
              message: 'Authentication FAILED!'       
          })
          
      }
  }
  
  module.exports = authenticate
  </code></pre>
  <p>And, now find below the code I use to render:</p>
  <pre><code>.
  .
  .
  const authenticate = require('./authentication/authenticate.js');
  .
  .
  .
  .
  
  app.get('/list', authenticate, async (req,res)=&gt; {
  
      let countyResult = await county();
      let transId = await transactionId();
      
      transModel.find({transIndustry: 'Pharmacy'}, (err, docs)=&gt; {
      if (!err) 
          {
              res.render('list',  {data : docs, countyName: countyResult, transId: transId}); 
          }
      else
          {
  //          res.status(status).send(body);      
          }
              
      })
  });
  </code></pre>
  <p>However, when I try to access the endpoint/link/address above via the browser, I get this error message:</p>
  <pre><code>{&quot;message&quot;:&quot;Authentication FAILED!&quot;}
  </code></pre>
  <p>I feel like this is an <strong>Authorization value</strong> issue, and I don't quite know how I should be passing this value when rendering the <code>list</code> page via <code>res.render('list',  {data : docs, countyName: countyResult, transId: transId});</code>.</p>
  <p>Looking forward to your help.</p>