修复 SSE 成员校验未生效的问题

This commit is contained in:
2026-03-03 12:14:38 +08:00
parent 724be69c76
commit 67fdf7427a
5 changed files with 59 additions and 24 deletions
+18 -8
View File
@@ -12,15 +12,25 @@ export async function GET(
const url = new URL(req.url);
const userId = url.searchParams.get("userId");
if (!userId) {
return new Response(JSON.stringify({ error: "missing_user_id" }), {
status: 401,
headers: { "Content-Type": "application/json" },
});
}
if (userId) {
const data = await getRoomData(id);
if (data && !data.users.includes(userId)) {
return new Response(JSON.stringify({ error: "not_a_member" }), {
status: 403,
headers: { "Content-Type": "application/json" },
});
}
const data = await getRoomData(id);
if (!data) {
return new Response(JSON.stringify({ error: "room_not_found" }), {
status: 404,
headers: { "Content-Type": "application/json" },
});
}
if (!data.users.includes(userId)) {
return new Response(JSON.stringify({ error: "not_a_member" }), {
status: 403,
headers: { "Content-Type": "application/json" },
});
}
const encoder = new TextEncoder();