const jwt = require('jsonwebtoken');

module.exports = (req, res, next) => {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return res.sendStatus(403);
  try {
    req.user = jwt.verify(token, 'secret123');
    next();
  } catch {
    res.sendStatus(403);
  }
};
