加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – AngularFire $requireAuth未检测到过期的身份验证

发布时间:2020-12-17 18:05:13 所属栏目:安全 来源:网络整理
导读:在谷歌搜索这个问题时,我发现 the following让我相信它不应该是一个问题,所以我确定我做错了什么但是无法解决. 有时我在身份验证过期后导航到我的应用程序时,它会加载页面而不是重定向到/ login,在控制台中我看到: Error: permision denied at /the/firebas
在谷歌搜索这个问题时,我发现 the following让我相信它不应该是一个问题,所以我确定我做错了什么但是无法解决.

有时我在身份验证过期后导航到我的应用程序时,它会加载页面而不是重定向到/ login,在控制台中我看到:

Error: permision denied at /the/firebase/url: Client doesn't have permission to access the desired data

如果我重新加载页面,我将按预期成功定向到/ login.

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',function(Auth){
                        return Auth.$requireAuth();
                    }],"list": ['$route','dao',function($route,dao){
                        return dao.getPrivateList($route.current.params.id).$loaded();
                    }],"items": ['$route',dao){
                        return dao.getListItems($route.current.params.id).$loaded();
                    }]
                }
            })
            .otherwise( {redirectTo: '/' });
    }]);

解决方法

您是否在运行块中处理$routeChangeError事件以告诉它重定向?

.run(function($rootScope,$location) {
    $rootScope.$on("$routeChangeError",current,eventObj) {
            if (eventObj === 'AUTH_REQUIRED') {
                console.log('auth required!');
                $location.path("/login");
            }
        }
    );
})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读