简体   繁体   English

Emberjs和Ember-Simple-Auth:如何手动将Auth Header添加到Dropzone.js文件上传

[英]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. 我正在用ember cli构建我的第一个emberjs(1.13.8)webapp,总的来说,我是这种框架的新手。 The app uses ember-simple-auth (0.8.0) and ember-simple-auth-token for token verification. 该应用程序使用ember-simple-auth(0.8.0)和ember-simple-auth-token进行令牌验证。 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. 但是现在我使用dropzone-js上载文件,并且授权标头未自动设置。 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? 我的问题现在是如何将刷新的令牌添加到文件中?

Your computed property should watch token changes. 您的计算属性应监视token更改。 Try that: 试试看:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM