title: (ReactJS) Getting error in Login Component, while Register Compo. works perfectly
body: <p>I can't seem to get why my Login component is getting an error when my Registration component works well while using the same POST request to the backend server. The only thing that they differ is the method of retrieving data from MongoDB in their backend script partner, which is what I am thinking is the problem, but anything I do doesn't seem to work.</p>
  <p>Edit &gt; * The error in the Login Component is AxiosError: Network Error. Both the Login and Register backend have been tested in Postman and works well, and responds a status. So it seems that the problem is in the Login React Component's Axios post request. It send data to the backend okay, but it catches an error after that.*</p>
  <p>The login script of the backend server is working well and validating the credentials perfectly. But then, React gets an error.</p>
  <p>in Login React Component (AxiosError):</p>
  <pre><code>async postReq() {
          const loginData = JSON.stringify(
              {
                  'email': this.state.email,
                  'password': this.state.password,
              },
          );
  
          console.log(loginData)
  
          let validation = await axios.post(
              'http://localhost:5000/login', 
              loginData, 
              { headers: {'Content-Type':'application/json'} 
          })
          .then((res) =&gt; {
              console.log(`Login successful. ${res}`);
              let response = res;
              this.props.redirect('/session');
          })
          .catch((error) =&gt; {
              console.log(error);
              console.log(`Cannot login. ${error.message}`)
              console.log(error.request);
              let response = error;
              alert(&quot;Damn.&quot;)
          });
  
      }
  </code></pre>
  <p>in Register React Component (works smoothly):</p>
  <pre><code>handleSubmit() {
          // POST to server
  
          const regData = JSON.stringify(
              {
                  'firstname': this.state.fname,
                  'lastname': this.state.lname,
                  'email': this.state.email,
                  'birthday': this.state.birthday,
                  'password': this.state.password,
                  'country': this.state.country,
                  'city': this.state.city,
                  'provstate': this.state.provstate,
                  'contactnum': this.state.contactnum,
                  'formpicture': this.state.img,
                  'disclcond': this.state.cond,
              },
          );
  
          console.log(regData)
  
          axios.post(
              'http://localhost:5000/register', 
              regData, 
              { headers: {'Content-Type':'application/json'} 
          })
          .then((res) =&gt; {
              console.log(`Registered successfully. ${res}`);
              setTimeout(() =&gt; this.props.redirect('/login'), 2000)
          })
          .catch((res) =&gt; {
              console.log(`Not registered. ${res}`)
              alert(&quot;Damn.&quot;)
          });
      
      }
  </code></pre>
  <p>NodeJS, Mongoose || Login backend:</p>
  <pre><code>const router = require('express').Router();
  let User = require('../db_models/user.model');
  
  router.route('/').get((req, res) =&gt; {
      res.sendStatus(200);
      res.end();
  })
  
  // If user submits login credentials, check database
  router.route('/').post((req, res) =&gt; {
      const email = req.body.email;
      console.log(email)
      const password = req.body.password;
      let accountMatched = null;
  
      async function checkPassword() {
          
          await User.findOne({ 'email' : email })
          .then(user =&gt; {
              if (user.password === password) {
                  console.log(`true ${user.email} :: ${user.password}`);
                  accountMatched = true;
                  res.sendStatus(200);
              } else {
                  console.log(`damn!! ${err}`)
                  res.sendStatus(404);
                  throw err
              }
          })
          .catch(err =&gt; console.log(err))
  
          accountMatched === true ? console.log('Passed') : res.send('Failed'); 
  
  
          res.end()
      }
  
      checkPassword();
      
  })
  
  module.exports = router;
  </code></pre>
  <p>Register backend:</p>
  <pre><code>const router = require('express').Router();
  let User = require('../db_models/user.model');
  
  router.route('/').get((req, res) =&gt; {
      res.send('hello hello');
      res.end();
  })
  
  // If user submits registration credentials, submit to database
  router.route('/').post((req, res) =&gt; {
      console.log(req.body)
      const firstname = req.body.firstname;
      const lastname = req.body.lastname;
      const email = req.body.email;
      const birthday = Date.parse(req.body.birthday);
      const password = req.body.password;
      const contactnum = req.body.contactnum;
      const country = req.body.country;
      const city = req.body.city;
      const provstate = req.body.provstate;
  
      // below only pass links
      const formpicture = req.body.formpicture;
      const disclcond = req.body.disclcond;
  
      const newUser = new User({
          firstname,
          lastname,
          email,
          birthday,
          password,
          country,
          city,
          provstate,
          contactnum,
          formpicture,
          disclcond,
      });
  
      newUser.save()
      .then(() =&gt; {
          console.log('User added.');
          res.sendStatus(200);
          res.end();
      })
      .catch(err =&gt; {
          console.log(`Damn, user not added. ${err}`);
          res.end();
      })
  
      
  });
  
  module.exports = router;
  </code></pre>
  <p>I would really appreciate some help.</p>