title: xhr.js:220 POST http://localhost:3000/EShop/register 400 (Bad Request)
body: <p>Trying to POST request to send data to database but it always shows 400 bad request.
  The AuthReducer file is as follow. Data is not getting posted when done in Frontend but its properly working when tested in postman api.</p>
  <pre><code>export const Register = (username, email , password) =&gt; async(disptach) =&gt; {
      try{
          disptach({type:REGISTER_USER_REQUEST})
  
          const config = {
              Headers:{
                  'Content-Type':'application/json'
              }
          }
          const { data } = await axios.post('/EShop/register', {username ,email , password} , config)
  
          disptach({
              type:REGISTER_USER_SUCCESS,
              payload:data.user
          })
          
      }catch(error){
          disptach({
              type:REGISTER_USER_FAIL,
              payload : error.response.data.message 
          })
      }
  } 
  </code></pre>
  <p>The register form is as follow..</p>
  <pre><code>import React, { useState, useEffect } from &quot;react&quot;;
  import { Link, useNavigate } from &quot;react-router-dom&quot;
  import { useSelector, useDispatch } from &quot;react-redux&quot;
  import Loader from &quot;./loader&quot;;
  import { Register } from &quot;../actions/UserAction&quot;;
  import &quot;../css-files/Account.css&quot;
  
  export default function register() {
  
      const [email, setemail] = useState('');
      const [password, setpassword] = useState('');
      const [username, setusername] = useState('');
      const disptach = useDispatch();
      const navigate = useNavigate();
      const { isAuthenticated, error, loading } = useSelector(state =&gt; state.user)
  
      useEffect(() =&gt; {
          if (isAuthenticated) {
              navigate('/account/login')
          }
      }, [disptach, isAuthenticated])
  
      const SubmitRegisterHandler = (e) =&gt; {
          e.preventDefault()
          disptach(Register(username, email, password))
      }
  
      return (
          &lt;div id=&quot;Account_container&quot;&gt;
              {loading ?
                  &lt;Loader /&gt;
                  :
                  &lt;div id=&quot;wrapper&quot;&gt;
                      &lt;div id=&quot;Wrap_First&quot;&gt;
                          &lt;img src=&quot;https://res.cloudinary.com/dqxozrie1/image/upload/v1659935744/eshop/online-registration-sign-up_gfb2gs.webp&quot; /&gt;
                      &lt;/div&gt;
                      &lt;div id=&quot;Wrap_Second&quot;&gt;
                          &lt;div id=&quot;login&quot;&gt;
                              &lt;h2&gt;Create New Account&lt;/h2&gt;
                              &lt;form onSubmit={SubmitRegisterHandler}&gt;
                                  &lt;input
                                      required
                                      type=&quot;text&quot;
                                      placeholder=&quot;Username&quot;
                                      value={username}
                                      onChange={(e) =&gt; { setusername(e.target.value) }}
                                  /&gt;
                                  &lt;input
                                      required
                                      type=&quot;email&quot;
                                      placeholder=&quot;Email&quot;
                                      value={email}
                                      onChange={(e) =&gt; { setemail(e.target.value) }}
                                  /&gt;
                                  &lt;input
                                      required
                                      type=&quot;password&quot;
                                      placeholder=&quot;Password&quot;
                                      value={password}
                                      onChange={(e) =&gt; { setpassword(e.target.value) }}
                                  /&gt;
                                  &lt;button&gt;Register&lt;/button&gt;
                              &lt;/form&gt;
                              &lt;p id=&quot;existing_acc&quot;&gt;&lt;Link to=&quot;/account/login&quot;&gt;Already have an account !&lt;/Link&gt;&lt;/p&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              }
          &lt;/div&gt;
      );
  }
  </code></pre>
  <p>It gives 400 bad request always. Please help me how to resolve this issue.</p>