RafaelVidaurre / angular-permission

Simple route authorization via roles/permissions
MIT License
1.13k stars 212 forks source link

no $stateChangePermissionStart after upgrading to @uirouter/angularjs && angular-permission 5.3.2 #452

Closed NitsanBaleli closed 5 years ago

NitsanBaleli commented 5 years ago

Looking at the source code it seems no event is fired like in the older version.

Errors are catched inside the $transitions.onError function, but is there anyway to know that a permission was rejected ?

Thank you for your work ;)

Semkoo commented 5 years ago

$rootScope.$on('$stateChangePermissionDenied', function(event, toState, toParams, options) { ... });

https://github.com/RafaelVidaurre/angular-permission/wiki/Emitted-events-in-ui-router

NitsanBaleli commented 5 years ago

@Semkoo AFAIK these events aren't being broadcast when you use uirouter1.x, that's the issue Im facing

Semkoo commented 5 years ago

Honestly, I was running into a few bugs and I decided to follow this guide and now I am happy with it

http://adamalbrecht.com/2014/09/22/authorization-with-angular-and-ui-router/ Then when you are comparing the permissions https://stackoverflow.com/questions/16312528/check-if-an-array-contains-any-element-of-another-array-in-javascript var findOne = function (haystack, arr) { return arr.some(function (v) { return haystack.indexOf(v) >= 0; }); };

Use any CoffeeScript online compiler to convert into ES2015 to understand it better, happy coding

NitsanBaleli commented 5 years ago

Any updated on this please? I currently have no way of knowing if a $transitions.onError was caused by angular-permission.

Thanks again

NitsanBaleli commented 5 years ago

just to better explain the situation, there's no notification before this library redirects to the redirect.state in line 85 of angular-permission-ui.js

NitsanBaleli commented 5 years ago

My bad, Im closing this issue, lib works as advertised ;)

$transitions.onError({ to: 'app.**' }, ($transition$: Transition) => {
  const nextState = {
    state: $transition$.$to().name,
    params: $transition$.params('to')
  };
  window.sessionStorage.setItem(DENIED_ROUTE_SESSION_STORAGE_KEY, JSON.stringify(nextState));
});