修复 SSE 成员校验未生效的问题
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user