feat: socket target can also be string

This commit is contained in:
Methapon2001 2025-03-31 17:31:44 +07:00
parent b2ac1878b9
commit 63aea8dc27

View file

@ -40,8 +40,8 @@ export async function sendWebSocket(
event: string,
data: any,
opts?: {
roles?: string[];
userId?: string[];
roles?: string | string[];
userId?: string | string[];
},
) {
if (!io) initWebSocket();
@ -59,6 +59,9 @@ export async function sendWebSocket(
if (!user) continue;
if (typeof opts?.roles === "string") opts.roles = [opts.roles];
if (typeof opts?.userId === "string") opts.userId = [opts.userId];
if (
user.role?.some((v) => opts?.roles?.includes(v)) ||
opts?.userId?.some((v) => user.sub === v)