Q
Q
Quambaras2021-01-18 19:44:16
Express.js
Quambaras, 2021-01-18 19:44:16

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'})
    }
}

The problem is somewhere in the if block. If you output user to the console, then it is displayed in the if block, outside it is not. There is a constant Sending request... , no errors fall. what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2021-01-18
@YuriyVorobyov1333

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 question

Ask a Question

731 491 924 answers to any question