refactor: improve websocket log

This commit is contained in:
moonrailgun 2024-09-30 14:50:37 +08:00
parent ee72f74e2c
commit b44e57dde8

View File

@ -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;