fix: check chat/vote ownership during actions (#847)
This commit is contained in:
parent
c58fd528fc
commit
a378757d3b
4 changed files with 28 additions and 2 deletions
|
|
@ -58,7 +58,12 @@ export async function POST(request: Request) {
|
|||
const title = await generateTitleFromUserMessage({
|
||||
message: userMessage,
|
||||
});
|
||||
|
||||
await saveChat({ id, userId: session.user.id, title });
|
||||
} else {
|
||||
if (chat.userId !== session.user.id) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
}
|
||||
|
||||
await saveMessages({
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ export async function POST(request: Request) {
|
|||
|
||||
return Response.json(document, { status: 200 });
|
||||
}
|
||||
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { auth } from '@/app/(auth)/auth';
|
||||
import { getVotesByChatId, voteMessage } from '@/lib/db/queries';
|
||||
import { getChatById, getVotesByChatId, voteMessage } from '@/lib/db/queries';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
|
|
@ -15,6 +15,16 @@ export async function GET(request: Request) {
|
|||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const chat = await getChatById({ id: chatId });
|
||||
|
||||
if (!chat) {
|
||||
return new Response('Chat not found', { status: 404 });
|
||||
}
|
||||
|
||||
if (chat.userId !== session.user.id) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const votes = await getVotesByChatId({ id: chatId });
|
||||
|
||||
return Response.json(votes, { status: 200 });
|
||||
|
|
@ -38,6 +48,16 @@ export async function PATCH(request: Request) {
|
|||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const chat = await getChatById({ id: chatId });
|
||||
|
||||
if (!chat) {
|
||||
return new Response('Chat not found', { status: 404 });
|
||||
}
|
||||
|
||||
if (chat.userId !== session.user.id) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
await voteMessage({
|
||||
chatId,
|
||||
messageId,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export default defineConfig({
|
|||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||
forbidOnly: !!process.env.CI,
|
||||
/* Retry on CI only */
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
retries: process.env.CI ? 2 : 1,
|
||||
/* Opt out of parallel tests on CI. */
|
||||
workers: process.env.CI ? 1 : undefined,
|
||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue