title: Passing authentication token to HTML pages
body: <p>I have a user authentication system that generates an access token upon successful authentication. I need to pass this token to other pages as the header parameter to allow usage of that page.</p>
  <pre><code>    module.exports.authenticate=function(req,res){
          var email=req.body.email;
          var password=req.body.password;
         
         
          connection.query('SELECT * FROM org WHERE email = ?',[email], function (error, results, fields) {
            if (error) {
                res.json({
                  status:false,
                  message:'query error'
                  })
            }else{
             
              if(results.length &gt;0){
                  if(bcrypt.compareSync(password, results[0].password)){
                    
                    var access_token = jwt.sign({ id: email }, 'secretpassword123', {expiresIn: 3600});
                    var decoded = jwt.decode(access_token, 'secretpassword123');
                    var expires_in = decoded.exp-decoded.iat;
                    var token_type = &quot;org&quot;;
                    console.log(decoded);
                    req.headers.access_token = access_token;
                    res.cookie('access-token', access_token, { expires: new Date(Date.now() + 3600)})
                
  res.status(200).send({ auth: true, access_token: access_token, expires_in, token_type});
                 }
                  else{
                      res.json({
                        status:false,
                        message:&quot;Email or password does not match&quot;
                       });
                  }
                
              }
      
              else{
                connection.query('SELECT * FROM client WHERE email = ?',[email], function (error, results, fields) {
                  if (error) {
                    res.json({
                      status:false,
                      message:'query error'
                    })
                  }else{
                    if(results.length &gt;0){
                      if(bcrypt.compareSync(password, results[0].password)){
                        var access_token = jwt.sign({ id: email }, 'secretpassword123', {expiresIn: 3600});
                        var decoded = jwt.decode(access_token, 'secretpassword123');
                        var expires_in = decoded.exp-decoded.iat;
                        var token_type = &quot;client&quot;;
                        //res.status(200).send({ auth: true, access_token: access_token, expires_in, token_type});
                        connection.query('UPDATE client SET fingerprint = ?', access_token, function(error, results, fields){
                                  if(error){
                                      console.log(error);
                                  }
                                  else{
                                      console.log(results);
                                  }
                              })
                        return res.redirect('/dashboard.html');
                      }
                      else{
                        res.json({
                          status:false,
                          message:&quot;Email and password does not match&quot;
                        });
                      }
                    }
                    else{
                      res.json({
                        status:false,    
                        message:&quot;Email does not exist&quot;
                      });
                    }
                  }
                });
              }
            }
          });}
  </code></pre>
  <p>I want to pass the <code>access-token</code> to other pages and controllers as a way to authorize.</p>
  <p>For example, this is my get-user controller:</p>
  <pre><code>module.exports.getUser = function(req,res){
      var email = req.body.email;
      req.headers.access_token = authenticate.authenticate.access_token
      connection.query('SELECT clientid, email, orgid, name, phone, type, role, fingerprint, verified FROM client WHERE email = ?', req.body.email, function(error,results, fields){
                  if(error){
                      console.log(error)
                      res.redirect('/dashboard.html');
                  }
                  else{
                      console.log(req.headers)
                      console.log(results)
                      //res.redirect('/dashboard.html');
                      res.status(200).send(results);
                  }
              })
  }
  </code></pre>
  <p>How should I approach this?</p>
  <p>I have added <code>res.cookie</code> to the authentication module, and I can see that the cookie gets stored in the browser. But when I try to read the cookie in another page with <code>req.cookies</code> or <code>req.signedCookies</code> it says undefined.</p>
  <p>I ended up using localStorage to store the tokens. This is obviously not secure by oAuth standards, but it works. How can I use cookies to get the same functionality as local storage. I need to use the token generated in the authentication module to verify authorization in other pages.</p>