const jwt = require("jsonwebtoken");

const auth = (req, res, next) => {
  try {
    const getToken = req.headers.authorization.replace("Bearer ", "");

    const verifiedToken = jwt.verify(getToken, process.env.jwt_sec);

    req.user = verifiedToken;
  } catch (e) {
    res.status(401).json({
      status: "failed",
      message: "Access Denied Due To Invalid Token",
    });
    return;
  }

  next();
};
module.exports = auth;
