Extend AjaxService Headers
mapeveri opened this issue · 2 comments
Hi, i have this service for set token in the headers, like this:
// service/ajax.js
import { inject as service} from '@ember/service';
import { computed } from "@ember/object";
import AjaxService from 'ember-ajax/services/ajax';export default AjaxService.extend({
session: service('session'),headers: computed('session.content.authenticated.token', { get() { let headers = {}; const authToken = this.get('session').session.content.authenticated.token; if (authToken) { headers['Authorization'] = `jwt ${authToken}`; } return headers; } })
});
But it never executes the computed and does not send the token with make a ajax request. For example:
this.get('ajax').request('url', {
method: 'POST',
data: params
})
This line:
this.get('session').session.content.authenticated.token
return the token, if i go to component that make the request.
Is there an error in the AjaxService or am I doing wrong ?.
Thanks!
When you add the host property, it works perfectly.
Having same issue. Also havehost
property set in my service, but headers wont recompute when my session was changed. Currently fixed by adding .volatile()
after headers definition headers: computed(...).volatile()
, which causes to recalculate headers on each request