EDIT×2角度UIルータ - 約束し、あなたの提案に続いて、再帰的なリダイレクト問題が
、私は多くの変更を行いました。
今回は本当に約束しましたが、いくつか問題がありました。私は最終的に私は今、私の約束の作品を期待リダイレクトのためにそれを作った
// If it is, return true
else {
console.log('Valid token');
deferred.resolve(true); // Removed "return"
}
}
// If there's no valid token, return false
else {
console.log('No token');
$localStorage.$reset();
$state.go('login');
deferred.reject(false); // Removed "return"
}
:私はこれを変更しなければならなかった
// If it is, return true
else {
console.log('Valid token');
return deferred.resolve(true);
}
}
// If there's no valid token, return false
else {
console.log('No token');
$localStorage.$reset();
$state.go('login');
return deferred.reject(false);
}
:あなたはこのためにいくつかの時点では動作しませんでした提案は何
...
// Watching login page
$transitions.onStart({to: 'login'}, function (trans) {
// Injecting the authentication service
var auth = trans.injector().get('AuthService');
// returning the promise with handlers
return auth.isAuthenticated().then(function (res) {
// If the token is valid, redirect to the dashboard
return trans.router.stateService.target('dashboard.home');
}, function(e) {
// If the token is invalid or missing, keep the login page
return trans.router.stateService.target;
});
});
// Watching the dashboard private page
$transitions.onStart({to: 'dashboard.**'}, function (trans) {
// Injecting the authentication service
var auth = trans.injector().get('AuthService');
// returning the promise with handlers
return auth.isAuthenticated().then(function (res) {
// If the user is correctly identified, do nothing
return trans.router.stateService.target;
}, function (e) {
// If the token is invalid or missing, deleting datas
$localStorage.$reset();
// Setting error message
$localStorage.loginError = {'token_expired': true};
// Redirecting to the login page
return trans.router.stateService.target('login');
})
});
にリダイレクトを処理します。上のコードでは、約束を返せません。 –
こんにちはShaiilendra、私はこのアドオンの1.0ベータ2版とちょっと混乱しています。私は新しいTransitionシステムがちょっと複雑になっています...これを手助けする例はありますか? 実際、ログインは正常に動作しています。トークンの確認と更新も問題ありません。私の問題は、認証されていない場合でもダッシュボードにアクセスするのを防ぎ、ログインインなしでダッシュボードに更新可能なトークンがまだ残っている場合に直接アクセスできるようにすることです。 これはこれが失敗するところです。私が最初のもの(delog user)を使っているだけならOKです。私は2つを置く場合、私は無限ループに入り、なぜ見ることができません! –