I have this code and I am getting this error - "Can not use keyword 'await' outside an async function":
async login() {
try {
this.$validator.validateAll().then((result) => {
if (result) {
this.state = 'LOADING';
this.response = [];
const authResponse = await axios.post('/api/auth/login', this.user);
const auth = authResponse.data;
if (auth.success) {
this.$authLoggedIn(auth);
this.$authRedirectToDefault();
} else {
this.response.push(auth.error);
this.state = 'ERROR';
}
}
});
} catch (error) {
this.state = 'ERROR';
this.response.push(error);
}
},
How can I resolve this? Been stuck on this for a couple of hours.
Thanks.