0
對不起(可能)愚蠢的問題。我對這個話題超級新!Ember-Simple-Auth:如何在ajax請求中注入令牌
我創建了一個自定義的授權:
import Ember from 'ember';
import Base from 'ember-simple-auth/authorizers/base';
export default Base.extend({
authorize: function(jqXHR, requestOptions) {
var accessToken = this.get('session.content.secure.token');
if (this.get('session.isAuthenticated') && !Ember.isEmpty(accessToken)) {
jqXHR.setRequestHeader('Authorization', 'Bearer ' + accessToken);
}
}
});
,現在我想在我的控制器中的Ajax請求的令牌(這是我的代碼,而無需令牌發送):
// app/controllers/workouts.js
import Ember from 'ember';
import config from '../config/environment';
export default Ember.Controller.extend({
requestEndpoint: config.ServerIp+'/workouts',
workouts: function() {
Ember.$.ajax({
type: "GET",
url: requestEndpoint
}).success(function(data) {
return data;
})
}.property()
});
非常感謝您幫助和理解這個偉大的模塊!