作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我搜索这个问题时,我发现 the following让我相信这不应该是一个问题,所以我确定我做错了什么,但就是无法解决。
有时,当我在身份验证过期后导航到我的应用程序时,它会加载页面而不是重定向到/login,并且在控制台中我会看到:
Error: permision denied at /the/firebase/url: Client doesn't have permission to access the desired data
angular.module('app',['firebase','ngRoute','ngAnimate','ui.bootstrap'])
.factory("Auth",function($firebaseAuth){
var ref = new Firebase("https://app.firebaseio.com");
return $firebaseAuth(ref);
})
.run(['$rootScope','$location','$window',function($rootScope,$location,$window){
$rootScope.$on('$routeChangeError',function(event,next,previous,error){
$location.path('/login');
});
if($window.localStorage.getItem('app-last-list')) {
$location.path('/lists/' + $window.localStorage.getItem('app-last-list'));
}
}])
.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/',{
templateUrl: 'views/list-view.html',
controller: 'ListViewController',
resolve: {
"currentAuth": ['Auth', function(Auth) {
return Auth.$requireAuth();
}]
}
})
.when('/login',{
templateUrl: 'views/login-view.html',
controller: 'LoginController'
})
.when('/lists/:id', {
templateUrl: 'views/list-items-view.html',
controller: 'ListItemsController',
resolve: {
"currentAuth": ['Auth',function(Auth){
return Auth.$requireAuth();
}],
"list": ['$route','dao',function($route,dao){
return dao.getPrivateList($route.current.params.id).$loaded();
}],
"items": ['$route','dao',function($route,dao){
return dao.getListItems($route.current.params.id).$loaded();
}]
}
})
.otherwise( {redirectTo: '/' });
}]);
最佳答案
您是否在运行块中处理 $routeChangeError 事件以告诉它重定向?
.run(function($rootScope, $location) {
$rootScope.$on("$routeChangeError",
function(event, current, previous, eventObj) {
if (eventObj === 'AUTH_REQUIRED') {
console.log('auth required!');
$location.path("/login");
}
}
);
})
关于angularjs - AngularFire $requireAuth 未检测到过期的身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39217486/
在我搜索这个问题时,我发现 the following让我相信这不应该是一个问题,所以我确定我做错了什么,但就是无法解决。 有时,当我在身份验证过期后导航到我的应用程序时,它会加载页面而不是重定向到/
我有以下路线和 requireAuth 实现。我有两个问题。 1.) I'm not being redirected from / to /login when I'm not logged in.
因此,我使用 firebase 中的 requireAuth() 来使用 gulpJs、angularJs 和Firebase 的原因。我对这三件事还很陌生。 requireAuth() 方法在我的应
我是一名优秀的程序员,十分优秀!