feat: socket target can also be string
This commit is contained in:
parent
b2ac1878b9
commit
63aea8dc27
1 changed files with 5 additions and 2 deletions
|
|
@ -40,8 +40,8 @@ export async function sendWebSocket(
|
||||||
event: string,
|
event: string,
|
||||||
data: any,
|
data: any,
|
||||||
opts?: {
|
opts?: {
|
||||||
roles?: string[];
|
roles?: string | string[];
|
||||||
userId?: string[];
|
userId?: string | string[];
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
if (!io) initWebSocket();
|
if (!io) initWebSocket();
|
||||||
|
|
@ -59,6 +59,9 @@ export async function sendWebSocket(
|
||||||
|
|
||||||
if (!user) continue;
|
if (!user) continue;
|
||||||
|
|
||||||
|
if (typeof opts?.roles === "string") opts.roles = [opts.roles];
|
||||||
|
if (typeof opts?.userId === "string") opts.userId = [opts.userId];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
user.role?.some((v) => opts?.roles?.includes(v)) ||
|
user.role?.some((v) => opts?.roles?.includes(v)) ||
|
||||||
opts?.userId?.some((v) => user.sub === v)
|
opts?.userId?.some((v) => user.sub === v)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue