skip to Main Content

When I click the button I send to the server and then the server responds to me but I can’t show it in Chrome console I can only see the response in the network tag.

Client:

const Login = async (e) => {
e.preventDefault();
await axios
  .post("http://localhost:5000/login", { userLogin })
  .then((res) => {
    console.log(res);
  });

};

Server:

  app.post("/login", (req, res) => {
  const { email, password } = req.body.userLogin;
  User.findOne({ username: email }).then((user) => {
    user.password == password
      ? res.json("Login successfully")
      : res.json("Your password or username is wrong");
  });
});

Network tag:

enter image description here

Can you guys help me please 🙁

2

Answers


  1. you can use console.log(res.data);

    Login or Signup to reply.
  2. You should return a json object like that

    app.post("/login", async  (req, res) => {
      try {
        const { email, password } = req.body.userLogin;
        const user = await User.findOne({ username: email });
      
        if (user.password == password)
          return res.json({ status: 200, msg: "Login successfully" });
        else
          return res.status(401).json({ msg: "Your password or username is wrong" });
      }
      catch (err) {
        return res.status(500).json({ msg: err.message })
      }
    });
    

    You can then show your error in browser console like that

    const Login = async (e) => {
      e.preventDefault();
      await axios
        .post("http://localhost:5000/login", { userLogin })
        .then((res) => {
          console.log('response', res);
        });
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search