In try to take value from axios post request but return [promise object]

Viewed 21

I'm try to get the return value from my route in golang api,, that return an id.

my route :

POST: http://localhost:1323/profile/valid

my axios request:

export async function validLogin(email, password) { 

  const data = JSON.stringify({ email, password });
  let headers = {
    'Content-Type': 'application/json;charset=UTF-8',
  };

  await axios.post('http://localhost:1323/profile/valid', data, headers)
  .then(response => {
    return response.data;
  })
  .catch(err =>{
    console.log(err);
  });

}

the function works, but return [promise object] or undefined.

1 Answers

The async function always returns Promise. To extract the data out of this function, call await for the promise returned above from another async function.

Related