0

mean.io has integrated authentication and it's working ok, but it has public and private pages. What can be done to force authentication for all pages (including public ones) so that user is instantly redirected to login?

4

1 回答 1

0

我也许可以使用这里解释的拦截器 http://djds4rce.wordpress.com/2013/08/13/understanding-angular-http-interceptors/

但随后需要弄清楚如何检查用户是否已登录并转发请求

angular.module('MyApp', [])
.config(function ($provide, $httpProvider) {
  $provide.factory('MyHttpInterceptor', function ($q) {
    return {
      request: function (config) {
        return config || $q.when(config);
      },
      // On request failure
      requestError: function (rejection) {
        return $q.reject(rejection);
      },
      response: function (response) {
        return response || $q.when(response);
      },
      responseError: function (rejection) {
        return $q.reject(rejection);
      }
    };
  });
  $httpProvider.interceptors.push('MyHttpInterceptor');
});
于 2014-05-23T21:27:50.683 回答