【问题标题】:AngularJS authenticating multiple routes with resolveAngularJS 通过解析验证多个路由
【发布时间】:2013-07-04 11:00:03
【问题描述】:

我正在尝试对应用程序中大多数路由的用户进行身份验证。

有没有办法在所有路线上全局执行此操作?所以我不需要以下内容:

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

在每个$routeProvider.when() 通话中。

【问题讨论】:

  • 这个HTTP Auth Interceptor Module 可能会有所帮助,即使它不能完全满足您的需求。
  • 谢谢。这实际上是一种非常有用的方法...

标签: javascript php angularjs model-view-controller url-routing


【解决方案1】:

Gloopy 的建议非常有趣,我将来可能会实施类似的方法。

现在我采取了一种更简单的方法:

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
    });

}]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 1970-01-01
    • 2015-02-02
    • 2017-11-24
    • 1970-01-01
    相关资源
    最近更新 更多