I'm relatively new to this and don't understand why this error is happening. I am trying to call an axios post request to access a database and let a user login, but the promise is not acting as expected. It will access the database and give back an object, but whenever I try to assign "result" below, it says result is still an empty object with a __proto__ object inside, even though console.log(result) will print out the data I want. How can I get the data I need into the "result" object instead of it just being an empty variable?
I've attached my code here:
const userlogin = {
company: this.state.company,
email: this.state.email,
password: this.state.password
}
let result = {}
axios.post('http://localhost:5000/login', userlogin)
.then(res => {
console.log(res.data[0])
result = res.data[0]
})
.catch(res => {
console.log("Failed")
})
console.log(result)
window.location = '/'
Printing res.data[0] prints exactly what I want, but when I assign it to the result and print result, it displays an empty object with the __proto__. I've been struggling with this for a while, and any help would be greatly appreciated! Thank you so much!