{"size": 458, "ext": "js", "max_stars_repo_path": "src/middlewares/authorization.js", "max_stars_repo_name": "JG-OLIVEIRA/levameulivro-backend", "max_stars_repo_stars_event_min_datetime": "2021-12-12T13:49:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-25T05:44:00.000Z", "max_issues_repo_path": "src/middlewares/authorization.js", "max_issues_repo_name": "JG-OLIVEIRA/levameulivro-backend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/middlewares/authorization.js", "max_forks_repo_name": "JG-OLIVEIRA/levameulivro-backend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.8095238095, "max_line_length": 65, "alphanum_fraction": 0.5829694323}
const jwt = require("jsonwebtoken");

module.exports = (req, res, next) => {
  const token = req.headers.authorization?.split(" ")[1];

  const decoded = jwt.verify(
    token,
    process.env.JWT_KEY,
    function (err, decoded) {
      if (err) {
        return res.status(401).send({
          messege: "Sessão expirada, por favor, logue novamente",
        });
      }
      return decoded;
    }
  );
  req.headers.authorization = decoded;
  next();
};
