requireAuth を機能させるのに苦労しています。ngroute と uirouter の両方を試しましたが、ユーザーがログインしない場合は、ホームページにリダイレクトしたいだけです。
私のアプリには、上記のルールを設定したい複数のコントローラーを含むページが 1 つあります。
これは、ファクトリおよび実行メソッドです。
app.factory("AuthFactory", ["$firebaseAuth", function($firebaseAuth) {
var ref = new Firebase("https://torrid-heat-237.firebaseio.com");
return $firebaseAuth(ref);
}
]);
// for ui-router
app.run(["$rootScope", "$state", function($rootScope, $state) {
$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
// We can catch the error thrown when the $requireAuth promise is rejected
// and redirect the user back to the home page
if (error === "AUTH_REQUIRED") {
$state.go("/");
}
});
}]);
その、私は .state メソッドを書きました:
app.config(["$stateProvider", function ($stateProvider) {
$stateProvider
.state('geniuses', {
url: '/geniuses',
abstract: true,
controller: 'GetAllGeniuses',
templateUrl: "views/listAllgeniuses",
resolve: {
"currentAuth": ["AuthFactory", function(AuthFactory) {
return AuthFactory.$requireAuth();
}]
}
}).state('geniuses', {
url: '/geniuses',
abstract: true,
controller: 'SearchAGenius',
templateUrl: "views/listAllgeniuses",
resolve: {
"currentAuth": ["AuthFactory", function(AuthFactory) {
return AuthFactory.$requireAuth();
}]
}
})
}]);
最後に、両方のコントローラーで、AuthFactory.requireAuth が解決されるのを待っています。しかし、ログインせずにURLにアクセスすると、そこにとどまり、ログインしても同じ種類のページが表示されます..
ここで私が間違ったことをしたのは正確には何ですか?