[Vuejs]-TypeError: Cannot set properties of undefined (setting 'Authorization')

-1👍

Your token should be inside the Bearer like this:

beforeCreated() {
    const token = localStorage.getItem("token")         

    if (token) {
        axios.defaults.headers.common['Authorization'] = `"Bearer ${token}"`

    } else {
        axios.defaults.headers.common['Authorization'] = ""
    }
}

Leave a comment