Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Robinvm's avatar

Vue Axios response undefined error

axios .post('/auth/login', {username: username, password: pass}, ).then(function (response) { console.log(response); }).catch(function (error) { console.log(error); }); Does anyone know why response is undefined Responds is good, success, but i cant access the response data

0 likes
1 reply
ejdelmonico's avatar

Are you returning anything from a successful login like the user? Assuming you are, you should have that data in response.data, not response. Also, it might work better if you wrap it in a promise.

(credentials) => {
  return new Promise((resolve, reject) => {
    axios.post('/auth/login', credentials)
             .then((response) => resolve(response.data))
             .catch((err) => reject(err));
  });
}

Please or to participate in this conversation.