Skip to content
Snippets Groups Projects
Commit aee72b35 authored by Lucas Gabriel Lima's avatar Lucas Gabriel Lima
Browse files

update API responses to match use cases's

parent daab538b
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!25Auth
Pipeline #
...@@ -150,8 +150,15 @@ userApp.post('/', (req, res, next) => { ...@@ -150,8 +150,15 @@ userApp.post('/', (req, res, next) => {
}); });
userApp.post('/authenticate', (req, res, next) => { userApp.post('/authenticate', (req, res, next) => {
if (!req.body.email || !req.body.password) { if (!req.body.email) {
res.json({success: false, msg: 'Please pass email and password.'}); res.json({success: false, msg: 'O campo Email é obrigatório.'});
} else {
next();
}
}, (req, res, next) => {
if (!req.body.password) {
res.json({success: false, msg: 'O campo Senha é obrigatório.'});
} else { } else {
next(); next();
} }
...@@ -163,7 +170,7 @@ userApp.post('/authenticate', (req, res, next) => { ...@@ -163,7 +170,7 @@ userApp.post('/authenticate', (req, res, next) => {
if (err) throw err; if (err) throw err;
if(!user){ if(!user){
res.json({success: false, msg: 'Authentication failed. User not found.'}); res.json({success: false, msg: 'O Email informado não está cadastrado.'});
} }
else { else {
user.comparePassword(req.body.password, (err, isMatch) => { user.comparePassword(req.body.password, (err, isMatch) => {
...@@ -174,10 +181,10 @@ userApp.post('/authenticate', (req, res, next) => { ...@@ -174,10 +181,10 @@ userApp.post('/authenticate', (req, res, next) => {
var token = jwt.encode(user, secret); var token = jwt.encode(user, secret);
//returns user info including token as json //returns user info including token as json
res.json({success: true, token: 'JWT ' + token}); res.json({success: true, token: 'JWT ' + token, msg: 'Usuário autenticado com sucesso'});
} }
else { else {
res.json({success: false, msg: 'Authentication failed. Wrong password'}); res.json({success: false, msg: 'A Senha informada é inválida.'});
} }
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment