Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Im trying to authenticate users for most routes in my application.

is there a way to do it globally on all routes? so i do not need to have the following:

resolve : {
    //This function is injected with the AuthService where you'll put your authentication logic
    'auth' : function(AuthService){
        return AuthService.authenticate();
    }
}

on each $routeProvider.when() call.

share|improve this question
1  
This HTTP Auth Interceptor Module may help even if it doesn't fit your need perfectly. –  Gloopy Jul 7 '13 at 6:14
    
thanks. that is actually a very helpful approach... –  AndrewMcLagan Jul 7 '13 at 9:30
add comment

1 Answer

the suggestion by Gloopy was very interesting, and i may implement a similar approach in the future.

For now i have taken a much simpler approach:

gm.config(['$routeProvider', 'PathProvider', function($routeProvider, PathProvider) {

    var authResolver = { // although this does work there could be a better way to do this.
        'auth' : function(AuthenticationService) {
            return AuthenticationService.isLoggedIn();
        }
    };

    $routeProvider.when('/authenticatedRoute', { 
        templateUrl: PathProvider.view('application/dashboard/index.html'), 
        controller: 'dashboardController',
        resolve: authResolver
    }); 

    $routeProvider.otherwise({ 
        redirectTo: '/dashboard',
        resolve: authResolver
    });

}]);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.