Permissions Evaluated Do Not Wait For UI-Router Resolve To Finish
Closed this issue ยท 6 comments
uiRouter Resolve Documentation
Resolve
"You can use resolve to provide your controller with content or data that is custom to the state. resolve is an optional map of dependencies which should be injected into the controller.
If any of these dependencies are promises, they will be resolved and converted to a value before the controller is instantiated and the $stateChangeSuccess event is fired."
Because angular-permission integrates with ui-router, I have an expectation that it will delay evaluation of permissions until resolve phase is complete.
QUESTION) How do I delay evaluation of the permission rules?
I use the word 'evaluation', as the permission definitions are already 'defined'.
Why? I want to delay permission evaluation, because:
- The data we need (which permissions need to be evaluated upon) hasn't been retrieved via AJAX yet by other pieces of code.
- We don't want our permission code to be promise aware; we'd like to avoid the coupling of business logic with data retrieval.
I find this to only be an issue on page load.
Thanks! :)
This should help you solve your problem::
https://github.com/Narzerus/angular-permission/wiki/Controlling-access-in-views#async-calls-for-permissions-in-initial-states
Thank you!
Interestingly for me and my team, this approach of using $urlRouterProvider.deferIntercept();
wasn't working for a while. We recently discovered that using "ui-router-extras": "0.1.3"
caused deferIntercept() to not defer correctly.
Our solution, remove ui-router-extras
, which is end of life anyway as of May 16, 2017.
Keeping up-to-date libs versioning is vital in every project ๐
This doesnt really address the problem.. Its kind of hard to not use UI router if the user hasnt yet logged in. So i need urlRouter to work off the bat. i have a resolve on my parent route to load permissions, but angular-permissions is hitting the deeply nested route before my resolves run..
In your angular-permissions-ui.js file, i modified line 62 to be
$transitions.onEnter({}, handleOnBeforeWebHook);
rather than
$transitions.onBefore({}, handleOnBeforeWebHook);
This solves my issue.. Not sure what the side effects are yet however, but this waits for the resolves to finish before loading.
The important tip here. Keep in mind that your app does not have to have only one root. You can create separate one for authorization to avoid additional hooks.