Angularjs AngularFire 身份验证的无限摘要循环
Angularjs inifinity digest loop on AngularFire authentication
求助!我想知道如何阻止它?使用 angular ui-router & angularFire 后,我遇到了无限摘要循环的问题。我发现循环不断陷入 $stateChangeStart 甚至调用登录状态。这是我的控制台日志。
1476969257159 Start: {} -> dashboard{}
Auth errorAUTH_REQUIRED
1476969259545 Start: {} -> login{}
1476969260671 Start: {} -> dashboard{}
Auth errorAUTH_REQUIRED
1476969263828 Start: {} -> login{}
1476969266255 Start: {} -> dashboard{}
我用这种方式编码我的 ui-router
$rootScope.$on("$stateChangeError",function (ev,toSt,toPa,fromSt,fromPa,error) {
// We can catch the error thrown when the $requireSignIn promise is rejected
console.log("Auth error" + error);
if (error === "AUTH_REQUIRED") {
$state.go("login");
}
});
和
$urlRouterProvider
.when('/', '/dashboard')
.when('','/')
.otherwise('/404');
我有的状态,
$stateProvider
.state('dashboard', {
url: '/dashboard',
controller: 'dashboardCtrl',
templateUrl: 'templates/dashboard/dashboard.html'
resolve: {
// controller will not be loaded until $requireSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the factory below
"currentAuth": ["wifAuth", function(wifAuth) {
// console.log ("dashboard check");
// $requireSignIn returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
return wifAuth.$requireSignIn();
}]
}
})
.state('login',{
url: '/login',
templateUrl: 'templates/auth/login.html',
resolve: {
// controller will not be loaded until $waitForSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the factory below
"currentAuth": ["wifAuth", function(wifAuth) {
// console.log ("login check");
// $waitForSignIn returns a promise so the resolve waits for it to complete
return wifAuth.$waitForSignIn();
}]
}
})
我通过添加
解决了它
event.preventDefault ()
停止仪表板状态
if (error === "AUTH_REQUIRED") {
//halt default event then initiate state go to new nested page
event.preventDefault();
// as of now, we go to login until landing template is up
$state.go("landing");
// $state.go("login");
}
求助!我想知道如何阻止它?使用 angular ui-router & angularFire 后,我遇到了无限摘要循环的问题。我发现循环不断陷入 $stateChangeStart 甚至调用登录状态。这是我的控制台日志。
1476969257159 Start: {} -> dashboard{}
Auth errorAUTH_REQUIRED
1476969259545 Start: {} -> login{}
1476969260671 Start: {} -> dashboard{}
Auth errorAUTH_REQUIRED
1476969263828 Start: {} -> login{}
1476969266255 Start: {} -> dashboard{}
我用这种方式编码我的 ui-router
$rootScope.$on("$stateChangeError",function (ev,toSt,toPa,fromSt,fromPa,error) {
// We can catch the error thrown when the $requireSignIn promise is rejected
console.log("Auth error" + error);
if (error === "AUTH_REQUIRED") {
$state.go("login");
}
});
和
$urlRouterProvider
.when('/', '/dashboard')
.when('','/')
.otherwise('/404');
我有的状态,
$stateProvider
.state('dashboard', {
url: '/dashboard',
controller: 'dashboardCtrl',
templateUrl: 'templates/dashboard/dashboard.html'
resolve: {
// controller will not be loaded until $requireSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the factory below
"currentAuth": ["wifAuth", function(wifAuth) {
// console.log ("dashboard check");
// $requireSignIn returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
return wifAuth.$requireSignIn();
}]
}
})
.state('login',{
url: '/login',
templateUrl: 'templates/auth/login.html',
resolve: {
// controller will not be loaded until $waitForSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the factory below
"currentAuth": ["wifAuth", function(wifAuth) {
// console.log ("login check");
// $waitForSignIn returns a promise so the resolve waits for it to complete
return wifAuth.$waitForSignIn();
}]
}
})
我通过添加
解决了它event.preventDefault ()
停止仪表板状态
if (error === "AUTH_REQUIRED") {
//halt default event then initiate state go to new nested page
event.preventDefault();
// as of now, we go to login until landing template is up
$state.go("landing");
// $state.go("login");
}