Answer the question
In order to leave comments, you need to log in
Why is there a Sending request... and no code is being executed?
const bcrypt = require('bcrypt');
const User = require('name.json');
const registration = () => async (req, res, next) => {
try {
const salt = await bcrypt.genSalt(10)
const hashPassword = await bcrypt.hash(req.body.password, salt);
const candidate = await User.some(e => e.login === req.body.login);
if(!candidate){
const user = {id: req.body.id, role: req.body.role, login: req.body.login, password: hashPassword};
console.log(user)
return
}
else {
res.status(401).send({message:"User exist"})
}
next();
} catch (e) {
res.status(401).send({message: 'Error'})
}
}
Answer the question
In order to leave comments, you need to log in
If you output user to the console, then it is displayed in the if block, outside it is not.outside it and will not be, because the scope of the variable is limited by the if block. Also in the if block you do a return and immediately exit the function, what result do you expect?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question