in

I am getting "xhr.js:210 POST http://localhost:5000/api/users 400 (Bad Request)" response while using axios.post from action in react


I am using axios.post in my auth action by which I want to post my register detail that I am getting from register component . But I am getting bad request response and with error

"Error: Request failed with status code 400
    at createError (createError.js:16)
    at settle (settle.js:17)
    at XMLHttpRequest.onloadend (xhr.js:66)"

Please find the below code for my Auth action and Register component and please let me know the mistake that I making here :

//auth action :

import axios from "axios";
import {setAlert} from './alerts';
import {REGISTER_FAIL,REGISTER_SUCCESS} from './types';



// Register User  
export const register =  ({name,email,password}) => async (dispatch) =>  {

    
    
  const headers = {
    'Content-Type': 'application/json'
  
  }
  

    const body=JSON.stringify({name,email,password});
    
   console.log(body);
 
    try {
      const res = await axios.post('http://localhost:5000/api/users', body, {
      headers: headers
    })
      dispatch({
        type: REGISTER_SUCCESS,
        payload: res.data
      });
      
    } catch (err) {
      const errors = err.response.data.errors;
  /*
     if (errors) {
       errors.forEach((error) => dispatch(setAlert(error.msg, 'danger')));
      }
      */
     console.log(err);
  
      dispatch({
        type: REGISTER_FAIL
      });
    }
   
    



  };
  // , "proxy": "http://localhost:5000"

// Register component

import React from 'react';
import { useState } from 'react';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
import { setAlert } from '../../actions/alerts';
import { register} from '../../actions/auth';//importing register action
import './../../App.css';
export const Register = (props) => {

    const [formData, setFormData] = useState({
      name:'',
      email:'',
      password:'',
      password2:''
     })

    const {name,email,password,password2}={...formData};

    const onChange=(e)=>setFormData({...formData,[e.target.name]:e.target.value});

    const onSubmit=(e)=>{
     e.preventDefault();
     if(password!==password2){
         props.setAlert('password do not match','danger');
     }
     else{
       
         props.register({name,email,password});
     }
    }

    return (
        <div >
            <h1 className="large text-primary">Sign Up</h1>
      <p className="lead"><i className="fas fa-user"></i> Create Your Account</p>
      <form className="form" onSubmit={e=>onSubmit(e)}>
        <div className="form-group">
          <input type="text" placeholder="Name"
           name="name" value={name}
            onChange={e=>onChange(e)} 
            required />
        </div>
        <div className="form-group">
          <input type="email"
           placeholder="Email Address" 
           name="email" value={email}
            onChange={e=>onChange(e)} />
          <small className="form-text"
            >This site uses Gravatar so if you want a profile image, use a
            Gravatar email</small
          >
        </div>
        <div className="form-group">
          <input
            type="password"
            placeholder="Password"
            name="password"
            value={password}
            onChange={e=>onChange(e)}
            minLength="6"
          />
        </div>
        <div className="form-group">
          <input
            type="password"
            placeholder="Confirm Password"
            name="password2"
            value={password2}
            onChange={e=>onChange(e)}
            minLength="6"
          />
        </div>
        <input type="submit" className="btn btn-primary" value="Register" />
      </form>
      <p className="my-1">
        Already have an account? <Link to="/login">Sign In</Link>
      </p>
        </div>
    )
}


export  default  connect(null,{setAlert,register}) (Register);



Source: https://stackoverflow.com/questions/70556656/i-am-getting-xhr-js210-post-http-localhost5000-api-users-400-bad-request

A Python App generate ,save , find and delete passwords

An Encrypted overlay filesystem written in Golang