【发布时间】:2014-07-30 15:24:41
【问题描述】:
我在从一位高级开发人员那里继承的项目中使用 Hot Towel 角度库 (https://github.com/johnpapa/hottowel-angular-bower)。
我还在为 Angular 合并 Auth0 的身份验证库。
我需要将一些路由限制为经过身份验证的用户。为此,我设置了一些路由属性。isLogin: true 用于仅限未经身份验证的用户的路由。requiresLogin: true 用于需要身份验证的路由,而对于那些不需要身份验证的路由则相反。为了在每次运行时检查这些属性,我使用$rootScope.$on('$routeChangeStart' function())。
app.run(function ($rootScope, $location, auth, common, config) {
var getLogFn = common.logger.getLogFn,
log = getLogFn('auth handle'),
events = config.events;
$rootScope.$on('$routeChangeSuccess', function (e, nextRoute, currentRoute) {
if (nextRoute.$$route && nextRoute.$$route.settings && nextRoute.$$route.settings.requiresLogin) {
if (!auth.isAuthenticated) {
$location.path('/login');
log('User not authenticated');
}
}
if (nextRoute.$$route && nextRoute.$$route.settings && nextRoute.$$route.settings.isLogin) {
if (auth.isAuthenticated) {
$location.path('/');
log('User is authenticated');
}
}
})
});
现在,这似乎干扰了 Hot-Towel 附带的微调器功能。在 Shell.js 中,我发现以下内容:
$rootScope.$on('$routeChangeStart',
function (event, next, current) { toggleSpinner(true); }
);
$rootScope.$on(events.controllerActivateSuccess,
function (data) { toggleSpinner(false); }
);
$rootScope.$on(events.spinnerToggle,
function (data) { toggleSpinner(data.show); }
);
会发生什么情况是微调器永远不会停止旋转(例如 vm.isBusy = true,因为控制器永远不会被激活并重置它),我将如何解决这个问题?
【问题讨论】:
标签: javascript angularjs authentication hottowel