diff --git a/server/src/auth/logout.js b/server/src/auth/logout.js index 31afe83..0315bbd 100644 --- a/server/src/auth/logout.js +++ b/server/src/auth/logout.js @@ -1,7 +1,8 @@ -import { logger, userRoom } from "../util.js"; +import { logger, sessionRoom } from "../util.js"; export function logout({ app, io }) { app.post("/logout", (req, res, next) => { + const sessionId = req.session.id; const userId = req.user.id; req.logout((err) => { @@ -9,9 +10,13 @@ export function logout({ app, io }) { return next(err); } - logger.info("user [%s] has logged out", userId); + logger.info( + "user [%s] has logged out from session [%s]", + userId, + sessionId, + ); - io.in(userRoom(userId)).disconnectSockets(); + io.in(sessionRoom(sessionId)).disconnectSockets(); res.status(204).end(); }); diff --git a/server/src/index.js b/server/src/index.js index b18f809..13c5559 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -18,7 +18,13 @@ import { getUser } from "./user/get.js"; import { initAuth } from "./auth/index.js"; import { reachUser } from "./user/reach.js"; import { searchUsers } from "./user/search.js"; -import { channelRoom, userRoom, userStateRoom, logger } from "./util.js"; +import { + channelRoom, + userRoom, + userStateRoom, + logger, + sessionRoom, +} from "./util.js"; const CLEANUP_ZOMBIE_USERS_INTERVAL_IN_MS = 60_000; @@ -88,6 +94,7 @@ function initEventHandlers({ io, db, config }) { }); socket.join(userRoom(socket.userId)); + socket.join(sessionRoom(socket.request.session.id)); next(); }); diff --git a/server/src/util.js b/server/src/util.js index e3a47d0..34db3b5 100644 --- a/server/src/util.js +++ b/server/src/util.js @@ -42,6 +42,10 @@ export function userRoom(userId) { return `user:${userId}`; } +export function sessionRoom(sessionId) { + return `session:${sessionId}`; +} + export function userStateRoom(userId) { return `user_state:${userId}`; }