I'm trying to implement client-side authentication with AngularJS. Right now I'm injecting the access-levels for each route as a factory into the config function of my app. Here is my code:
shop = angular.module('shop', ['ngCookies']).
provider('AccessLevels',function () {
var accessLevels = {
guest: 7,
customer: 6,
seller: 4
};
return {
$get: function () {
return accessLevels
}
}
}).
config(['$routeProvider', '$locationProvider', 'AccessLevelsProvider', function ($routeProvider, $locationProvider, AccessLevelsProvider) {
var accessLevels = AccessLevelsProvider.$get();
$routeProvider.
when('/index', {templateUrl: "pages/index", controller: IndexController, access: accessLevels.guest}).
when('/user', {templateUrl: "pages/user", controller: UserController, access: accessLevels.customer}).
when('/sign_up', {templateUrl: "pages/sign_up", controller: SignUpController, access: accessLevels.guest});
}]);
Is it possible to get the data for my access-levels with a $http.get request? I can't inject $http into my provider function so I'm a little bit helpless at the moment.
Any help would be appreciated.