mikemclin / angular-acl

Role-based permissions for AngularJS
196 stars 49 forks source link

Does it work with ui-router #15

Open amrinder23 opened 8 years ago

amrinder23 commented 8 years ago

Hi Mike,

Can i use it in an application using ui-router for routing.

Regards Amrinder

mikemclin commented 8 years ago

@amrinder23 I m not as familiar with UI Router. I can figure it out and post here eventually (I'm getting ready to leave for work). In the meantime, I'd suggest searching "angular ui router protect routes" or something similar to see the mechanism for bailing out of a route based on some sort of logic. Then I'd implement this angular-acl package into that flow.

If you find a good solution, please share :smile:

yhonguevara commented 8 years ago

@amrinder23 If you use !, the only thing different is the statement app.run ()

app.run(['$rootScope', '$state', function ($rootScope, $state) {
  // If the route change failed due to our "Unauthorized" error, redirect them
  $rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, rejection) {
    if (rejection === 'Unauthorized') {
      $state.go('home');
    }
  });
}]);
mikemclin commented 8 years ago

@yhon92 thanks for the comment :+1:

amrinder23 commented 8 years ago

Thanks @yhon92 .. I will try this. :+1:

amrinder23 commented 8 years ago

Thanks @mikemclin for an awesome service. Thanks @yhon92 it worked for me. $state didnt work in app.run method. I had to get its instance using $injector.get("$state"). Then it worked for me.

amrinder23 commented 8 years ago

@mikemclin .. Just another question. After implementing angular-acl in my application, when i refresh the browser it considers it as $stateChangeError and it goes into that code block (rejection==='Unauthorized') and sets the current state to the one set there.

Can't we remain on the same state ?

yhonguevara commented 8 years ago

@amrinder23 1) what version you're using ui-router?

2) I use $stateChangeStart to capture the event to load the browser, and if the key there AclService in the localStorage use the function AclService.resume(); to continue operation.

amrinder23 commented 8 years ago

@yhon92 I am using v0.2.15 of ui-router