Browse Source

[fix] error if user not found/invalid pass

master
Muthu Kumar 4 years ago
parent
commit
ef58c48017
Signed by: mkrhere GPG Key ID: 3FD688398897097E
  1. 29
      index.js

29
index.js

@ -97,14 +97,31 @@ const getProot = () =>
}
const user = await User.findOne({ username: req.body.username });
const valid = await bcrypt.compare(req.body.password, user.password);
if (user) {
const valid = await bcrypt.compare(
req.body.password,
user.password,
);
if (valid) {
const token = uuid();
user.tokens.push(token);
await user.save();
if (valid) {
const token = uuid();
user.tokens.push(token);
await user.save();
res.send({ success: true, token });
res.send({ success: true, token });
} else {
res.statusCode = 401;
res.send({
success: false,
msg: "Error! Username or password was wrong.",
});
}
} else {
res.statusCode = 401;
res.send({
success: false,
msg: "Error! Username or password was wrong.",
});
}
});

Loading…
Cancel
Save