Neah version calendar fix 3
This commit is contained in:
parent
6b425506ae
commit
181bdfaf2a
@ -30,7 +30,7 @@ export async function GET(
|
|||||||
) {
|
) {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
if (!session?.user?.username) {
|
if (!session?.user?.id) {
|
||||||
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
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 });
|
return NextResponse.json({ error: "Non autorisé" }, { status: 403 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export async function GET(
|
|||||||
) {
|
) {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
if (!session?.user?.username) {
|
if (!session?.user?.id) {
|
||||||
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
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
|
// 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 });
|
return NextResponse.json({ error: "Non autorisé" }, { status: 403 });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ export async function DELETE(
|
|||||||
) {
|
) {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
if (!session?.user?.username) {
|
if (!session?.user?.id) {
|
||||||
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ export async function DELETE(
|
|||||||
const calendar = await prisma.calendar.findFirst({
|
const calendar = await prisma.calendar.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: params.id,
|
id: params.id,
|
||||||
userId: session.user.username,
|
userId: session.user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { prisma } from "@/lib/prisma";
|
|||||||
*
|
*
|
||||||
* The function performs the following steps:
|
* The function performs the following steps:
|
||||||
* 1. Retrieves the server session using `getServerSession`.
|
* 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.
|
* - 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.
|
* 3. Attempts to fetch the calendars associated with the authenticated user from the database.
|
||||||
* - If successful, returns the calendars in a JSON response.
|
* - If successful, returns the calendars in a JSON response.
|
||||||
@ -20,14 +20,14 @@ import { prisma } from "@/lib/prisma";
|
|||||||
export async function GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
if (!session?.user?.username) {
|
if (!session?.user?.id) {
|
||||||
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const calendars = await prisma.calendar.findMany({
|
const calendars = await prisma.calendar.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: session.user.username,
|
userId: session.user.id,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
events: {
|
events: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user