text: const jwt = require("jsonwebtoken");
  const config = require("config");
  
  // Middleware - intercept inbound data and checks for token validation.
  module.exports = (req, res, next) => {
      if(req.method === "OPTIONS") {
          // next() continues request process.
          return next();
      }
  
      try{
          const token = req.headers.authorization.split(" ")[1];
          
          if(!token) {
              return res.status(401).json({message: "Not authorized"});
          }
  
          // Decodes passed token.
          const decoded = jwt.verify(token, config.get("jwtSecret"));
          req.user = decoded;
          next();
      } catch (e) {
          return res.status(401).json({message: "Not authorized"});
      }
  }