const jwt = require("jsonwebtoken");
const config = require("config");
const { CompanyUsers } = require("../models/CompanyUsers");
const { Company } = require("../models/Company");

module.exports = async function (req, res, next) {
  console.log("REQUEST host: ", req.headers.host); //BaseURl
  try {
    let company = await Company.findOne({ domain: req.headers.host });
    if (!company) {
      console.log("No company found");
      return res.status(400).send("No company found.");
    }
    req.company = company;
    return next();
  } catch (err) {
    console.log("ERR: ", err);
    return res.status(400).send("Error in validating token");
  }
};
