From b44e57dde8d027eb05b7e8db20d490d2b62607cc Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 30 Sep 2024 14:50:37 +0800 Subject: [PATCH] refactor: improve websocket log --- src/server/ws/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/server/ws/index.ts b/src/server/ws/index.ts index bc2643a..c2c67c4 100644 --- a/src/server/ws/index.ts +++ b/src/server/ws/index.ts @@ -29,6 +29,11 @@ export function initSocketio(httpServer: HTTPServer) { if (token) { user = jwtVerify(token); + logger.info( + '[WebSocket] Authenticated via JWT:', + user.id, + user.username + ); } else { const session = await getAuthSession( socket.request, @@ -43,10 +48,13 @@ export function initSocketio(httpServer: HTTPServer) { username: session.user.name, role: session.user.role, }; + logger.info( + '[WebSocket] Authenticated via Session:', + user.id, + user.username + ); } - logger.info('[Socket] Authenticated via JWT:', user.id, user.username); - socket.data.user = user; socket.data.token = token;