token y cambios al reporte
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const { crearToken } = require('../../middleware/autentificacion');
|
||||
const Admin = require('../../db/tablas/Admin');
|
||||
const { comparar } = require('../../helper/encriptar');
|
||||
|
||||
@@ -12,14 +13,21 @@ const login = async (body) => {
|
||||
|
||||
return Admin.findOne({
|
||||
where: { usuario: body.usuario },
|
||||
}).then((res) => {
|
||||
if (!comparar(password, res.password))
|
||||
throw new Error('La contraseña es incorrecta.');
|
||||
return Admin.findOne({
|
||||
where: { usuario: body.usuario },
|
||||
attributes: ['usuario'],
|
||||
});
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!comparar(password, res.password))
|
||||
throw new Error('La contraseña es incorrecta.');
|
||||
return Admin.findOne({
|
||||
where: { usuario: body.usuario },
|
||||
attributes: ['usuario'],
|
||||
});
|
||||
})
|
||||
.then((res) => ({
|
||||
Usuario: res,
|
||||
token: crearToken({
|
||||
idUsuario: numeroCuenta,
|
||||
}),
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = login;
|
||||
|
||||
Reference in New Issue
Block a user