Neah version calendar fix
This commit is contained in:
parent
ca4d86f238
commit
cb481a4f3f
@ -1,6 +1,6 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { getServerSession } from "next-auth/next";
|
import { getServerSession } from "next-auth/next";
|
||||||
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
|
import { authOptions } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { getServerSession } from "next-auth/next";
|
import { getServerSession } from "next-auth/next";
|
||||||
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
|
import { authOptions } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -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.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.
|
* - 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?.id) {
|
if (!session?.user?.username) {
|
||||||
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.id,
|
userId: session.user.username,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
events: {
|
events: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user