Socket.IO의 인증 기능을 사용하여 세션 데이터를 가져 오려고합니다. 문제는 내가 로그 아웃하여 내 세션을 파괴하더라도 Socket.IO에는 여전히 이전 세션 정보가 있기 때문에 명확하지 않습니다. 아래의 코드에서 내가 뭘 잘못하고 있는지 아이디어?Socket.io 인증 기능이 세션 데이터를 업데이트하지 않습니다.
io.sockets.on('connection', function(socket) {
var hs = socket.handshake;
console.log('A socket with sessionID ' + hs.sessionID
+ ' connected!');
// setup an inteval that will keep our session fresh
var intervalID = setInterval(function() {
// reload the session (just in case something changed,
// we don't want to override anything, but the age)
// reloading will also ensure we keep an up2date copy
// of the session with our connection.
hs.session.reload(function() {
// "touch" it (resetting maxAge and lastAccess)
// and save it back again.
hs.session.touch().save();
});
}, 60 * 1000);
socket.on('disconnect', function() {
console.log('A socket with sessionID ' + hs.sessionID
+ ' disconnected!');
// clear the socket interval to stop refreshing the session
clearInterval(intervalID);
});
});
+1 동일한 문제가 있습니다. 클라이언트의 세션 쿠키가 만료되거나 삭제 되더라도 Socket.IO 연결은 여전히 이전 데이터에 액세스 할 수 있으며 세션이 여전히 활성 상태라고 간주합니다. – dbau