Commit e2d42648 by Denys Tito Urbano

Middlewares agregados

parent 4d2b4e61
const { validate_errors } = require('../middlewares/validate_errors');
const { validate_jwt } = require('../middlewares/validate_jwt');
module.exports = {
validate_errors,
validate_jwt
};
\ No newline at end of file
const { validationResult } = require('express-validator');
const validate_errors = (req, res, next) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ status: false, errors: errors.array() });
}
next();
};
module.exports = {
validate_errors
};
\ No newline at end of file
const { verify } = require('jsonwebtoken');
const validate_jwt = async (req, res, next) => {
try {
const token = req.header('Authorization').replace('Bearer', '').trim();
if (!token) {
res.status(401).json({ message: 'No hay un token en la petición' });
}
const { documento } = verify(token, process.env.SECRET_KEY);
req.params.documento = documento;
next();
} catch (error) {
res.status(401).json({ message: 'Token no válido' });
}
};
module.exports = {
validate_jwt
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment