Alexander Kim
Alexander Kim

Reputation: 18382

API is not receiving my access token

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:

enter image description here

in request:

enter image description here

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:

enter image description here

Upvotes: 2

Views: 392

Answers (2)

Alexander Kim
Alexander Kim

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

Max Maximilian
Max Maximilian

Reputation: 600

Try defining headers before:

axios.defaults.headers.common = {
    'Authorization' : localStorage.getItem('access_token')
};

Upvotes: 1

Related Questions