E
E
Evergarden772021-06-07 08:57:38
Express.js
Evergarden77, 2021-06-07 08:57:38

Why is error status returned, but json file is not returned with it?

There is a piece of code that is responsible for authorizing the user. If I return a status with an error code, then Jason does not come with a message, if the status is removed, then everything is OK. How can I make it come and this and that? Not strong in backing...

UserModel.findOne({email:postData.email},(err,user: any) =>{
            if(err || !user) {
                return  res.status(404).json({
                    message:"error"
                });
            }
            if(bcrypt.compareSync(postData.password, user.password)){
                const token = CreateJWT(user);
                res.json({
                    status:"success",
                    token
                })
            } else {
                res.json({
                    status:"error",
                    message: "Неудача.. "
                })
            }
        })

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question