when i use localStorage i have this error : Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'token'). But my token is here :
Promise is here :
async loginSubmit () {
const response = axios.post('http://localhost:3000/api/auth/login', {
email: this.email,
password: this.password
});
localStorage.setItem('token', response.data.token);
console.log(response);
this.$router.push('actu');
},
Can you help me ? please
CodePudding user response:
Axios returns a promise, you need to await the request:
const response = await axios.post(...)
CodePudding user response:
You are using axios, it returns a promise. That's why you have this error. You have to use async await to wait for axios to respond
const response = await axios.post('http://localhost:3000/api/auth/login', {
email: this.email,
password: this.password
});