Skip to content

Commit

Permalink
fix: fix user controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Beor18 committed Aug 19, 2019
1 parent 961a7d9 commit c1874e7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions controllers/user.controller.js
Expand Up @@ -72,7 +72,7 @@ async function postLogin(req, res) {
await User.findOne({ email })
.then(user => {
if (!user) {
errors.email = 'User no encontrado'
errors.email = 'El usuario no existe'
return res.status(404).json(errors);
}
bcrypt.compare(password, user.password)
Expand All @@ -81,23 +81,22 @@ async function postLogin(req, res) {
const payload = {
id: user.id,
name: user.name,
role: user.role,
avatar: user.avatar
}
jwt.sign(payload, 'secret', {
expiresIn: 3600
}, (err, jwt) => {
if (err) console.error('Error en token', err);
else {

return res.status(200).json({
message: "Bienvenido " + user.name,
productos_url: '/api/productos',
jwt: `Bearer ${jwt}`
})
})
}
});
} else {
errors.password = 'Pass incorrecta';
errors.password = 'Contraseña incorrecta';
return res.status(400).json(errors);
}
});
Expand Down

0 comments on commit c1874e7

Please sign in to comment.