Skip to content

Commit 60794a5

Browse files
authored
Merge pull request #91 from pixie-git/bugfix/PIX-106_clear-canvas-not-working
PIX-106 fix: improve lobby owner authorization for canvas clearing by…
2 parents 901de58 + 7337e09 commit 60794a5

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

server/src/sockets/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,16 @@ export const setupSocket = (io: Server) => {
8181
if (!user || !user.id) return;
8282

8383
const lobby = await LobbyService.getById(lobbyId);
84-
if (!lobby || !lobby.owner) return;
84+
if (!lobby) return;
8585

86-
const ownerId = (lobby.owner as any)._id ? (lobby.owner as any)._id.toString() : lobby.owner.toString();
86+
let ownerId: string | null = null;
87+
if (lobby.owner) {
88+
ownerId = (lobby.owner as any)._id ? (lobby.owner as any)._id.toString() : lobby.owner.toString();
89+
}
90+
91+
const isOwner = ownerId && ownerId === user.id;
8792

88-
if (ownerId !== user.id && !user.isAdmin) {
93+
if (!isOwner && !user.isAdmin) {
8994
socket.emit(CONFIG.EVENTS.SERVER.ERROR, { message: "Only the lobby owner or admin can clear the canvas" });
9095
return;
9196
}

0 commit comments

Comments
 (0)