Search code examples
authenticationember.jsember-clidropzone.jsember-simple-auth

Emberjs and Ember-Simple-Auth: How to manually add Auth Header to Dropzone.js file upload


I'm building my first emberjs (1.13.8) webapp with ember cli and in general I'm new at this sort of framework. The app uses ember-simple-auth (0.8.0) and ember-simple-auth-token for token verification. Every request gets an authorization header automatically and this works very well. But now I use dropzone-js for uploading files and the authorization header isn't set automatically. So I have to add it manually. I have tried it with the following snippet which I copy and paste from my route's controller:

addHeaderEvent: Ember.computed(function() {
  return {"Authorization": "Bearer " + this.get('session').content.secure.token};
}),

This is working only until the auth token will be refreshed. After refreshing the token every file only gets the old token but all other request have the new one.

My Question is now how I can also add the refreshed token to my files?


Solution

  • Your computed property should watch token changes. Try that:

    addHeaderEvent: Ember.computed('session.content.secure.token', function() {
      return {"Authorization": "Bearer " + this.get('session').content.secure.token};
    }),