I am creating an authentication system with redux but getting POST http://localhost:5000/users/signup 400 (Bad Request) while requesting to backend for login but this link is working to login with help of postman and also getting axios error AxiosError {message: 'Request failed with status code 400', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}
This is the code of authSlice.js
import * as api from "../api"
export const login=createAsyncThunk("auth/login",async({formValue,navigate,toast})=>{
try{
const response=await api.signIn(formValue);
toast.success("success");
navigate("/");
return response.data;
}catch(err){
console.log(err)
}
})
const authSlice=createSlice({
name:"auth",
initialState:{
user:null,
error:"",
loading:false,
},
reducers:{
},
extraReducers:{
[login.pending]:(state,action)=>{
state.loading=true;
},
[login.fulfilled]:(state,action)=>{
state.loading=false;
localStorage.setItem("profile",JSON.stringify(...action.payload));
state.user=action.payload;
},
[login.rejected]:(state,action)=>{
state.loading=false;
state.error=action.payload.message;
},
}
});
export default authSlice.reducer;
This is the code of api.js
const API =axios.create({baseURL:"http://localhost:5000"});
export const signIn=(formData)=>API.post("/users/signup",formData);