text: const jwt = require('jsonwebtoken');
  
  // custom middleware for authentication
  
  const withAuth = function (req, res, next) {
    const token =
      req.body.token ||
      req.query.token ||
      req.headers['x-access-token'] ||
      req.cookies.token; if (!token) {
        res.status(401).send('Unauthorized: No token provided');
      } else {
      jwt.verify(token, process.env.SECRET, function (err, decoded) {
        if (err) {
          res.status(401).send('Unauthorized: Invalid token');
        } else {
          next();
        }
      });
    }
  }
  
  module.exports = withAuth;