【问题标题】:mean.io force authenticationmean.io 强制认证
【发布时间】:2014-05-23 19:57:55
【问题描述】:

mean.io 已集成身份验证,并且运行正常,但它有公共和私人页面。可以做些什么来强制对所有页面(包括公共页面)进行身份验证,以便立即将用户重定向到登录?

【问题讨论】:

    标签: angularjs passport.js mean-stack mean.io


    【解决方案1】:

    我也许可以使用这里解释的拦截器 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');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 2016-01-04
      • 2014-01-09
      • 2013-10-04
      • 1970-01-01
      • 2016-11-09
      • 2016-07-02
      相关资源
      最近更新 更多