0

I try to send a request with an email and a password with axios in react.` React app:

      console.log(`
    --SUBMITTING--
    First Name: ${this.state.firstName}
    Last Name: ${this.state.lastName}
    Email: ${this.state.email}
    Password: ${this.state.password}
  `);
  this.sendData(this.state.email, this.state.password);
  // this.changeRoot("calendar");
} else {
  console.error("FORM INVALID - DISPLAY ERROR MESSAGE");
}

};

  sendData(login, password) {
console.log("login -> " + login);
console.log("passwor -> " + password);
axios.post('http://localhost:9000/signup', { email: login, psswd: password })
.then((rep) => { console.log(rep) })
.catch((error) => { console.log(error) });

}

The data in login and password are OK. Node server :

app.post('/signup', (req, res, next) => {
console.log("login -> " + req.body.email);
console.log("psswd -> " + req.body.psswd);

});

So thank for all help.

  • 1
    May I know what is the issue/error you are facing? – wentjun Feb 06 '20 at 16:36
  • i have an error 500. and error like this in my terminal. TypeError: Cannot read property 'email' of undefined at /home/clementbl/Tek1/My_Project/Blooprint/blooprint/api/server.js:20:40 at Layer.handle [as handle_request] –  Feb 06 '20 at 20:12

1 Answers1

0

Just guessing, but, it looks like you are not configuring the bodyParser() middleware (the one that parses data from the HTTP request into the req.body)

Please see this related answer

tato
  • 5,439
  • 4
  • 31
  • 27