safak / youtube

5.04k stars 5.47k forks source link

NodeJS error: ERR_HTTP_HEADERS_SENT: Cannot set headers after they are sent to the client #95

Closed xvbnm48 closed 2 years ago

xvbnm48 commented 2 years ago

error when sending a request whose data is wrong, such as in the login route, after sending the wrong data request, an error occurs on the nodeJs server

example

!validPassword && res.status(400).json("wrong password");
xvbnm48 commented 2 years ago

for the solution is to make the logic on checking the password incorrectly with if and then returning the error message, for example like this:

if (!validPassword) {
      return res.status(400).json("wrong password");
}