后端发送的只是前端得到的数据,这太奇怪了。
当我尝试登录并注销帐户时,后端的会话将被清除,但即使在删除会话后,前端仍然可以接收会话数据。
在我的路由器中:
R
在我的服务工厂:
router.get('/session', getSession);
var getSession = function(req, res, next) {
console.log(req.session);
if(!req.user || req.user === undefined || !req.session || req.session === undefined) res.status(304).send({username: null, id: null, type: null, expires: null});
else res.status(200).send({username: req.session.username, id: req.session.passport.user, type: req.session.type, sidebar: req.session.sidebar, expires: req.session.cookie._expires});
}
然后我刷新登录页面, 控制台登录后端:
function ValidateSession(cb) {
$http.get('/session')
.success(function (res) {
console.log(res);
cb('OK');
})
.error(function(response){
if(!response.username || !response.id || !response.expires) {
ClearCredentials();
cb('NOSESSION');
}
else{
var now = new Date();
var expires = new Date(response.expires);
var expired = now.getTime() > expires.getTime() ? true : false;
if(expired) {
ClearCredentials();
cb('EXPIRED');
}
}
});
}
服务中的console.log:
Session {
cookie:
{ path: '/',
_expires: Wed Oct 05 2016 12:30:27 GMT+1100 (AUS Eastern Daylight Time),
originalMaxAge: 7200000,
httpOnly: true } }