const jwt = require('jsonwebtoken');

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

  if (token) {
    try {
      const decoded = jwt.verify(token, 'no-mdp');

      res.locals.matricule = decoded.userMatricule;
    } catch (err) {
      logger.log('error', `Erreur JWT : `, err.message);
    }
  }

  next();
};
