由于某种原因未设置“授权”标头。我尝试在 config/environment.js 中设置授权者
更新:根据@marcoow 的建议
ENV['simple-auth'] = {
crossOriginWhitelist: ['*'],
authorizer: 'simple-auth-authorizer:devise'
};
ENV['simple-auth-devise'] = {
serverTokenEndpoint: 'users/sign_in',
};
...我可以通过更新其他资源(例如 post Authorization: Token token="", user_email="" 未添加到我的服务器调用中来登录我的应用程序
控制器/dashboard.js
import Ember from 'ember';
export
default Ember.Controller.extend({
actions: {
add: function () {
var name = this.get('name');
var start = this.get('Start');
var end = this.get('End');
var game = this.store.createRecord('game', {
name: name,
start: start,
end: end
});
game.save();
}
}
});
我的请求看起来像这样
**1。我的理解是这里的请求标头也应该包含 Authorization: 标头。
- 我正在使用 rack-cors gem 来启用 cors
- 我查看了ember-simple-auth-devise / lib / simple-auth-devise / authorizers / devise.js 的来源。授权:函数()将此添加到请求中。我不确定如何调用此方法。
登录控制器
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export
default Ember.Controller.extend(LoginControllerMixin, {
authenticator: 'simple-auth-authenticator:devise',
actions: {
authenticate: function () {
console.log('i was called');
var self = this;
var data = this.getProperties('identification', 'password');
self.get('session').authenticate(this.get('authenticator'), data).then(function () {
self.transitionToRoute('dashboard');
}, function (error) {
console.log(error);
});
}
}
});
我可以看到:
我如何使用设计授权我的模型#save ....使用 ember-data
只是为了调试,我在 route/dashboard.js 中做了这个
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin,{
model: function() {
console.log(this.get('session.isAuthenticated')); # this is true
}
});