diff --git a/app/api/calendars/[id]/events/route.ts b/app/api/calendars/[id]/events/route.ts index 268ce1b..dc0e277 100644 --- a/app/api/calendars/[id]/events/route.ts +++ b/app/api/calendars/[id]/events/route.ts @@ -1,6 +1,6 @@ import { NextRequest, NextResponse } from "next/server"; import { getServerSession } from "next-auth/next"; -import { authOptions } from "@/app/api/auth/[...nextauth]/route"; +import { authOptions } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; /** diff --git a/app/api/calendars/[id]/route.ts b/app/api/calendars/[id]/route.ts index 25ea758..4f8f59d 100644 --- a/app/api/calendars/[id]/route.ts +++ b/app/api/calendars/[id]/route.ts @@ -1,6 +1,6 @@ import { NextRequest, NextResponse } from "next/server"; import { getServerSession } from "next-auth/next"; -import { authOptions } from "@/app/api/auth/[...nextauth]/route"; +import { authOptions } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; /** diff --git a/app/api/calendars/route.ts b/app/api/calendars/route.ts index 3449365..39b55c8 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.id`. + * 2. Checks if the user is authenticated by verifying the presence of `session.user.username`. * - 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?.id) { + if (!session?.user?.username) { return NextResponse.json({ error: "Non authentifié" }, { status: 401 }); } try { const calendars = await prisma.calendar.findMany({ where: { - userId: session.user.id, + userId: session.user.username, }, include: { events: {