0

when i use localStorage i have this error : Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'token'). But my token is here :

enter image description here

Promise is here :

enter image description 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

2 Answers 2

1

Axios returns a promise, you need to await the request:

const response = await axios.post(...)
0
0

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.