text: import * as jsonwebtoken from "jsonwebtoken";
  
  const jwt = jsonwebtoken.default;
  
  const { SECRET_SALT, WEB_WHITELIST_IP } = process.env;
  
  export default async (req, res) => {
    const knex = req.app.locals.knex;
    const session = req.cookies.session;
    if (!session) return false;
    try {
      const decrypted = jwt.verify(session, SECRET_SALT);
      if (decrypted.iat < Math.floor(Date.now() / 1000) - 60 * 60 * 24 * 365) {
        await knex("user_session").where("jwt", session).del();
        return false;
      }
      const sessions = await knex("user_session").where("jwt", session);
      if (!sessions.length) return false;
      if (sessions[0].id === 9 && req.ip !== WEB_WHITELIST_IP) return false;
      const { ASN, country } = res.locals;
      await knex("user_session").where("jwt", session).update({
        updated: new Date(),
        country_code: country.isoCode,
        country_name: country.names.en,
        ip_address: req.ip,
        ip_subnet: ASN.network,
        asn: ASN.autonomousSystemNumber,
        asn_name: ASN.autonomousSystemOrganization,
        agent: req.headers["user-agent"],
      });
      return true;
    } catch (e) {
      await knex("user_session").where("jwt", session).del();
      return false;
    }
  };
  