0
Great, I’m trying to make a wish POST
that in case of failure returns false
and in case of success returns true
.
My problem is because even with the await
does not expect that the Promise is resolved to return the value to the variable.
async login() {
this.userExist = await this.$root.login(this.email, this.password);
console.log("User -> " + this.userExist);
}
The variable always takes the value of undefined
.
The function this.$root.login()
is in the file vue.js
, and the function login
is in a component.
login(email, password) {
axios.post('/api/login',{email: email, password: password})
.then(response => {
sessionStorage.setItem('token', response.data.access_token);
this.$store.commit('define', response.data.access_token);
this.$router.push('/');
return true;
})
.catch(error => {
console.log(error);
return false;
});
}