0

I've made a MongoDB GET request route named users/auth to create authentication by searching for the records provided in the request's body, inside the database. When I send the request via POSTMAN then it gives the expected response (eg: "true") enter image description here

But when I tried to send the same request inside my react-app with AXIOS it gives an unexpected response(eg: false) with status code: ok. I'm not sure of what wrong I'm doing.

//some valid objects which should return true
//but it return's false
users = {
"email": 'abc@gm.com',
"password": 'abcdef'
}

axios.get('http://localhost:5000/users/auth', users)
        .then(res => {
            console.log(res.data);
  //expected: true
  // actual result: false
        })
        .catch(error => console.log(error))

I've read this problem but It didn't fixed my problem.

Uttam
  • 718
  • 6
  • 19
  • 1
    You're sending a get request in postman with a body? Usually the parameters are added to the URL for GET requests What happens if you add the values to the `Params` tab in postman instead and remove the body? – haldo Feb 05 '22 at 12:02
  • it return false(unexpected) :( Am I doing wrong in sending AXIOS request? – Uttam Feb 05 '22 at 15:09
  • Are you sure it should be a GET request? If it works with a body then try changing to POST in axios and postman (and put the params in the body). The other possibility is a bug server side. How do you know the server is responding correctly? – haldo Feb 05 '22 at 15:57
  • Because I've tested the endpoints with postman it's working fine. I want GET, hence POST will not work :( – Uttam Feb 05 '22 at 16:19
  • Can you check what value email and password are received on the server? – lowfront May 27 '22 at 16:58

0 Answers0