1

I am currently facing a problem in using angular-http-auth library which is handling a state transition from events of event:auth-loginRequired. I am using angular-ui-router for my routing systems.

Anyway here's some pieces of code from the library that emit the events :

case 401:
    var deferred = $q.defer();
    httpBuffer.append(config, deferred);
    $rootScope.$broadcast('event:auth-loginRequired', rejection);
    return deferred.promise;

And I was catching the events with these pieces of codes inside myApp.run

$rootScope.$on('event:auth-loginRequired', function(){
    console.log('Token Invalid / Expired');
    $state.transitionTo('login');
});

I was able to get the 'Token Invalid / Expired' inside my console. However, the state transition didn't work at all and I didn't get any errors on my console too. I've tried using $location.path('/login'), but it doesn't work too.

Can anyone please help me with the solutions? Any kind of help is really appreciated. Thanks!

Danny Pranoto
  • 214
  • 2
  • 12
  • Try using `$state.go` instead of `$state.transitionTo`. I believe it's the same but it sets some parameters by default. http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state – glcheetham Mar 31 '16 at 07:51
  • Thanks for the response! I've tried that too, but it still doesn't work :( – Danny Pranoto Mar 31 '16 at 08:07

1 Answers1

0

[UPDATE - SOLVED]

Sorry, I think I've found the solution, it's not because of the transition doesn't works inside Angular events, but I was so stupid that I myself have an event.preventDefault() handling whenever the app tried to redirect to login state (which I was trying to redirect when the app catches the events) if there's still a token inside the browser's cookies. I'm so sorry for the question.

Once again thank you for trying to help me!

Danny Pranoto
  • 214
  • 2
  • 12