From 181bdfaf2a65c61b39dc5242d4b8eaa8575ca53a Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 16 Apr 2025 21:08:05 +0200 Subject: [PATCH] Neah version calendar fix 3 --- app/api/calendars/[id]/events/route.ts | 4 ++-- app/api/calendars/[id]/route.ts | 8 ++++---- app/api/calendars/route.ts | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/api/calendars/[id]/events/route.ts b/app/api/calendars/[id]/events/route.ts index dc0e277..bbc3590 100644 --- a/app/api/calendars/[id]/events/route.ts +++ b/app/api/calendars/[id]/events/route.ts @@ -30,7 +30,7 @@ export async function GET( ) { const session = await getServerSession(authOptions); - if (!session?.user?.username) { + if (!session?.user?.id) { return NextResponse.json({ error: "Non authentifié" }, { status: 401 }); } @@ -49,7 +49,7 @@ export async function GET( ); } - if (calendar.userId !== session.user.username) { + if (calendar.userId !== session.user.id) { return NextResponse.json({ error: "Non autorisé" }, { status: 403 }); } diff --git a/app/api/calendars/[id]/route.ts b/app/api/calendars/[id]/route.ts index 9c8a708..cd20911 100644 --- a/app/api/calendars/[id]/route.ts +++ b/app/api/calendars/[id]/route.ts @@ -23,7 +23,7 @@ export async function GET( ) { const session = await getServerSession(authOptions); - if (!session?.user?.username) { + if (!session?.user?.id) { return NextResponse.json({ error: "Non authentifié" }, { status: 401 }); } @@ -42,7 +42,7 @@ export async function GET( } // Vérification que l'utilisateur est bien le propriétaire - if (calendar.userId !== session.user.username) { + if (calendar.userId !== session.user.id) { return NextResponse.json({ error: "Non autorisé" }, { status: 403 }); } @@ -144,7 +144,7 @@ export async function DELETE( ) { const session = await getServerSession(authOptions); - if (!session?.user?.username) { + if (!session?.user?.id) { return NextResponse.json({ error: "Non authentifié" }, { status: 401 }); } @@ -153,7 +153,7 @@ export async function DELETE( const calendar = await prisma.calendar.findFirst({ where: { id: params.id, - userId: session.user.username, + userId: session.user.id, }, }); diff --git a/app/api/calendars/route.ts b/app/api/calendars/route.ts index 39b55c8..3449365 100644 --- a/app/api/calendars/route.ts +++ b/app/api/calendars/route.ts @@ -11,7 +11,7 @@ import { prisma } from "@/lib/prisma"; * * The function performs the following steps: * 1. Retrieves the server session using `getServerSession`. - * 2. Checks if the user is authenticated by verifying the presence of `session.user.username`. + * 2. Checks if the user is authenticated by verifying the presence of `session.user.id`. * - If not authenticated, returns a 401 response with an error message. * 3. Attempts to fetch the calendars associated with the authenticated user from the database. * - If successful, returns the calendars in a JSON response. @@ -20,14 +20,14 @@ import { prisma } from "@/lib/prisma"; export async function GET(req: NextRequest) { const session = await getServerSession(authOptions); - if (!session?.user?.username) { + if (!session?.user?.id) { return NextResponse.json({ error: "Non authentifié" }, { status: 401 }); } try { const calendars = await prisma.calendar.findMany({ where: { - userId: session.user.username, + userId: session.user.id, }, include: { events: {