chore: add websocket for real time

This commit is contained in:
mahyargdz
2025-07-19 15:40:29 +03:30
parent 42f561f00c
commit 066d6c8598
25 changed files with 2360 additions and 636 deletions
@@ -0,0 +1,29 @@
import { Socket } from "socket.io";
/**
* Extracts authentication token from WebSocket client handshake
* Supports multiple token sources for flexibility
*
* @param client - Socket.IO client instance
* @returns Authentication token string or undefined if not found
*/
export function extractTokenFromClient(client: Socket): string | undefined {
// Priority order: auth.token > query.token > headers.authorization
const authToken = client.handshake?.auth?.token;
if (authToken) {
return authToken;
}
const queryToken = client.handshake?.query?.token;
if (queryToken && typeof queryToken === "string") {
return queryToken;
}
const authHeader = client.handshake?.headers?.authorization;
if (authHeader && typeof authHeader === "string") {
// Remove 'Bearer ' prefix if present
return authHeader.replace(/^Bearer\s+/i, "");
}
return undefined;
}