Reputation: 18382
fetchData () {
axios.get('https://some-address.com/orders', {
params: {
limit: this.limit,
offset: this.offset
},
headers: auth.getAuthHeader()
})
.then((resp) => {
this.req = resp.data
console.log(resp)
})
.catch((err) => {
console.log(err)
})
}
Storing token in "auth/index.js"
// The object to be passed as a header for authenticated requests
getAuthHeader () {
return {
'Authorization': localStorage.getItem('access_token')
}
}
When i send GET request to receive a list of items, i'm getting the following headers in response:
in request:
Status code 403, obviously API is not getting my access_token
. But if i make the same request in Postman (manually pasting access token value) - it works.
Error from console:
Upvotes: 2
Views: 392
Reputation: 18382
It was indeed issue on the backend side, thanks to @KirkLarkin, he pointed me in the right direction. I had to coordinate with backend developer for making correct headers for CORS requests.
Upvotes: 0
Reputation: 600
Try defining headers before:
axios.defaults.headers.common = {
'Authorization' : localStorage.getItem('access_token')
};
Upvotes: 1