I am struggling to figure out how to implement permissions and access control in our Angular app. Currently, our setup looks like this:
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('default', {
url: '',
templateUrl: 'pages/home/view/home.html',
controller: 'HomeCtrl'
})
.state('home', {
url: '/home',
templateUrl: 'pages/home/view/home.html',
controller: 'HomeCtrl',
permissions: { // ?
only: ['Admin','Moderator']
},
access: { // ?
roles: ['*']
},
resolve: { // ?
authenticate: function($state, $q, $timeout){
},
}
})
}]);
I am unsure of the best approach to take for implementing access control on each page.
Currently, the logged-in user information is stored within an Angular value:
app.value('USER', JSON.parse('{{{user}}}'));
The USER value contains details about the user's roles and permissions.
However, I am unable to inject USER into the app.config() callback as it returns an "unknown provider" error.
How can I enforce access control based on the parameters stored in the USER object?