nicklandgrebe / active-resource.js

ActiveResource.js - API resource relational mapping in JavaScript
https://active-resource.js.org
MIT License
133 stars 20 forks source link

Problem with setting Authorization header #37

Closed antonkomarev closed 5 years ago

antonkomarev commented 5 years ago

This code works:

let jsonApi = createResourceLibrary('http://127.0.0.1:8000', {
  headers: {
    Authorization: `${tokenType} ${accessToken}`,
  },
});

This one doesn't send headers when doing request:

let jsonApi = createResourceLibrary('http://127.0.0.1:8000');
jsonApi.headers = {
    Authorization: `${tokenType} ${accessToken}`,
};

And I've noticed that first example adds extra header:

'Content-Type': 'application/vnd.api+json',

While second one doesn't do it. And it seems that both examples doesn't use this header in requests.

Chilinot commented 5 years ago

I have the same issue. I cant get the requests to authenticate against the backend because i define the headers after the createResourceLibrary call.

nicklandgrebe commented 5 years ago

Sorry for the delay. I have uploaded the fix for this to master, and will update you when it is released as 1.0.0-beta.4

fconforti commented 5 years ago

@nicklandgrebe any updates for the 1.0.0-beta.4?

Thanks, F.