Closed arivasvera closed 8 years ago
Hi @andresrivas1506 , its already implemented by default, on protected routes you simply add
data { auth: true }
example: routes.config.js#L36
and to show / hide elements use vm.can()
nav-sidebar.component.html#L28 which is referenced on its controller nav-sidebar.component.js#L6
Hello @silverbux thanks for your time. Yes, its already implemented, but only using data { auth: true }
and showing/hiding things in template. If you go, for example, to url http://myapp/#/user-lists from url bar, you can see the html.
I want to protect the route using permissions:
.when('/content', {
resolve : {
'acl' : ['$q', 'AclService', function($q, AclService){
if(AclService.can('view_content')){
// Has proper permissions
return true;
} else {
// Does not have permission
return $q.reject('Unauthorized');
}
}]
}
});
Sorry for my bad english
I can solve with this:
$rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, rejection) {
if (rejection === 'Unauthorized') {
$state.go('app.landing');
}
});
.state('app.somerute', {
url: '/some-route',
resolve : {
'acl' : ['$q', 'AclService', function($q, AclService){
if(AclService.can('some_permission')){
// Has proper permissions
return true;
} else {
// Does not have permission
return $q.reject('Unauthorized');
}
}]
},
data: {
auth: true
},
views: {
'main@app': {
templateUrl: getView('someview')
}
}
})
Thank you @silverbux
Coolness, or try this approach as well.
data: {
auth: true,
access: 'manage.user'
}
then you could add a function on your /angular/run/routes.run.js and call AclService from there.
very nice that approach, thanks
can someone help me to use this https://github.com/mikemclin/angular-acl#protect-a-route to protect ui-routes?