问题:未经授权的请求不会使会话无效并转换为根网址。默认方法不起作用,所以我重写它。
我的自定义授权商
var CustomAuthorizer = Base.extend({
authorize: function(jqXHR, requestOptions) {
if (this.get('session.isAuthenticated') && !Ember.isEmpty(this.get('session.token'))) {
jqXHR.setRequestHeader('ApiKey', this.get('session.token'));
}
}
});
authorizationFailed hook
authorizationFailed: function(session){
console.log('authorizationFailed'); //displays in console
this.get('session').invalidate('authenticator:custom', {}); //doesn't invalidate
console.log(this.get('session')); //still return authenticated session
this.transitionTo('index'); //doesn't transition
}
我知道问题是因为失效是异步的,因此失效的承诺不会及时返回,以便console.log吐出无效的会话。还有另一种方法吗?
答案 0 :(得分:0)
invalidate
返回一个承诺,您应该等待转换前履行承诺。
this.get('session').invalidate('authenticator:custom', {}).then(function() {
this.transitionTo('index');
});