刷新页面后(angularJS,nodejs)失去身份验证



,所以我对我的Web应用程序有身份验证。这是我的身份验证控制器。

myTodoList.controller('authController', function($scope, $rootScope, $http, $location) {
$scope.user = { username: '', password: '' };
$scope.error_message = '';
$scope.login = function() {
    $http.post('/auth/login', $scope.user).success(function(data) {
        if (data.state == 'success') {
            $rootScope.authenticated = true;
            $rootScope.current_user = data.user.username;
            $location.path('/app');
        } else {
            $scope.error_message = data.message;
        }
    });
};
$scope.register = function() {
    $http.post('/auth/signup', $scope.user).success(function(data) {
        if (data.state == 'success') {
            $rootScope.authenticated = true;
            $rootScope.current_user = data.user.username;
            $location.path('/app');
        } else {
            $scope.error_message = data.message;
        }
    });
};

});

这很好,登录或进行新的注册后,我得到了身份验证。但是刷新页面后,我失去了身份验证。我认为这些行会产生问题。

var myTodoList = angular.module("myTodoList", ['ngRoute', 'ngResource']).run(function($http, $rootScope) {
$rootScope.authenticated = false;
$rootScope.current_user = 'Guest';
$rootScope.signout = function() {
    $http.get('auth/signout');
    $rootScope.authenticated = false;
    $rootScope.current_user = 'Guest';
};
});

在我的maincontroller.js的顶部,我有此$rootScope.authenticated = false;行。我知道这是需要的,但是这可能是说它应该是错误的,而不是刷新后是真的。我该怎么做才能解决这个问题?

,而不是将数据存储在Rootscope上,而是将其存储在会话速度中 - 这将持续浏览

https://github.com/gsklee/ngstorage

最新更新