我使用的是Angular.js 1.2.9。我在登录时创建了cookie。
$http.post('/api/login', $scope.new).then(function(response){
$cookieStore.put('token', response.data.token,{expires: new Date(2017, 21, 01)});
$rootScope.token=response.data.token;
$location.path('/dashboard');
}
当用户退出时,我将其删除:
$cookieStore.remove('token');
$rootScope.token=null;
注销后再次使用其他凭据登录,然后cookie没有获得更新。之后,当我按ctrl+R
[刷新页面]时,它会显示更新的用户数据,否则会显示旧用户的数据。
在标题中,我正在设置cookie的数据,我从db获取用户数据:
$httpProvider.interceptors.push(function($q, $cookieStore){
return{
'request':function(config){
config.headers.authorization = $cookieStore.get('token');
return config;
}
}
})
在我重新加载页面之前,控制台开发工具cookie没有被删除。