vendredi 1 avril 2016

How can I use ember-simple-auth to set header in custom url api with ember data?

My ember data model:

import DS from 'ember-data';
import config from './../config/environment';

export default DS.Model.extend({
  ...

  useRepairPackage(repairPackageId) {
    this.get('session').authorize('authorizer:digest', (headerName, headerValue)=> { 
      const headers = {}; 
      headers[headerName] = headerValue; 
      Ember.$.ajax({url: `${config.host}/${config.namespace}/quotations/${this.get('id')}/use_repair_package.json`, type: "PATCH", headers: headers}).then((result)=> { 
        return this.reload();
      }); 
    });
  }
});

I check ember-simple-auth document, I found this way to add session in header. But it can not work in model, and how can I add the seesion in this action? Thanks.




Aucun commentaire:

Enregistrer un commentaire