var testApp = angular.module('app', ['ngRoute']) .config(function($routeProvider){ $routeProvider.when('/', { templateUrl: '/angular/templates/operation/Index.html', controller: 'OperationController' }); $routeProvider.when('/Operation/:operationId/Details', { templateUrl: '/angular/templates/operation/Details.html', controller: 'OperationDetailsController' }); }); 

on the server ( application) there is a method that returns json in case the user is authorized or HttpStatusCode.Unauthorized

in order to restrict access to detailed information, I need to check the availability of appropriate privileges

 app.factory('accountService', ['$http',function($http){ return { getCredentials: function(){ let url = 'api/account/user'; return $http.get(url); } } }]); 

I do it like this:

 $routeProvider.when('/Operation/:operationId/Details', { templateUrl: '/angular/templates/operation/Details.html', controller: 'OperationDetailsController', resolve: { isAuthenticated: function(accountService){ accountService.getCredentials().then(function(){ return true; }, function(){ return false }); } } }); 

then in the controller I do this:

 app.controller('OperationDetailsController', function($scope, $location, isAuthenticated){ if(!isAuthenticated) $location.path('/Account/Login'); }) 

But it seems to me that I am doing something wrong / wrong. Tell me how to correctly implement the availability check on the client side.

PS: preferably with sample code. thank you in advance

    0