jeudi 12 février 2015

Ember Simple Auth - authorizationFailed not executing session invalidation or transitionTo

Problem: Unauthorized requests do not invalidate session and transition to root url. The default method isn't working so I'm overriding it.


My Custom Authorizer



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
}


I know that the problem is because the invalidation is asynchronous so the promise for the invalidation doesn't return in time for the console.log to spit out the invalidated session. Is there another way to do this?





Aucun commentaire:

Enregistrer un commentaire