mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(api): use sessionId instead of cookie to close sockets
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
import cookie from 'cookie';
|
||||
import * as cookieParser from 'cookie-parser';
|
||||
import signature from 'cookie-signature';
|
||||
import { SessionData } from 'express-session';
|
||||
import { Session as ExpressSession, SessionData } from 'express-session';
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { sync as uid } from 'uid-safe';
|
||||
|
||||
@@ -259,12 +259,10 @@ export class WebsocketGateway
|
||||
}
|
||||
|
||||
@OnEvent('hook:user:logout')
|
||||
disconnectSockets(sessionCookie: string) {
|
||||
if (sessionCookie.length) {
|
||||
for (const [socketId, socket] of this.io.sockets.sockets) {
|
||||
if (socket.handshake.headers.cookie?.includes(sessionCookie)) {
|
||||
this.io.sockets.sockets.get(socketId)?.disconnect(true);
|
||||
}
|
||||
disconnectSockets({ id }: ExpressSession) {
|
||||
for (const [, socket] of this.io.sockets.sockets) {
|
||||
if (socket.data['sessionID'] === id) {
|
||||
socket.disconnect(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user