Neah version calendar fix 3 debuger ???? ?????
This commit is contained in:
parent
88bb8a7f0a
commit
c9f7125f37
@ -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: {
|
||||||
|
|||||||
@ -3,6 +3,9 @@ import Imap from 'imap';
|
|||||||
import nodemailer from 'nodemailer';
|
import nodemailer from 'nodemailer';
|
||||||
import { parseEmailHeaders, decodeEmailBody } from '@/lib/email-parser';
|
import { parseEmailHeaders, decodeEmailBody } from '@/lib/email-parser';
|
||||||
import { cookies } from 'next/headers';
|
import { cookies } from 'next/headers';
|
||||||
|
import { getServerSession } from 'next-auth/next';
|
||||||
|
import { authOptions } from '@/lib/auth';
|
||||||
|
import { prisma } from '@/lib/prisma';
|
||||||
|
|
||||||
interface StoredCredentials {
|
interface StoredCredentials {
|
||||||
email: string;
|
email: string;
|
||||||
@ -92,11 +95,20 @@ function getStoredCredentials(): StoredCredentials | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
|
if (!session?.user?.id) {
|
||||||
|
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const credentials = getStoredCredentials();
|
const userCredentials = await prisma.emailCredentials.findUnique({
|
||||||
if (!credentials) {
|
where: { userId: session.user.id }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!userCredentials) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'No stored credentials found' },
|
{ error: 'No email credentials configured' },
|
||||||
{ status: 401 }
|
{ status: 401 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -110,10 +122,10 @@ export async function GET(request: Request) {
|
|||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const imap = new Imap({
|
const imap = new Imap({
|
||||||
user: credentials.email,
|
user: userCredentials.email,
|
||||||
password: credentials.password,
|
password: userCredentials.password,
|
||||||
host: credentials.host,
|
host: userCredentials.host,
|
||||||
port: credentials.port,
|
port: userCredentials.port,
|
||||||
tls: true,
|
tls: true,
|
||||||
tlsOptions: { rejectUnauthorized: false },
|
tlsOptions: { rejectUnauthorized: false },
|
||||||
authTimeout: 30000,
|
authTimeout: 30000,
|
||||||
|
|||||||
@ -41,3 +41,27 @@ model Event {
|
|||||||
@@index([calendarId])
|
@@index([calendarId])
|
||||||
@@index([userId])
|
@@index([userId])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model User {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
name String?
|
||||||
|
email String? @unique
|
||||||
|
emailVerified DateTime?
|
||||||
|
image String?
|
||||||
|
accounts Account[]
|
||||||
|
sessions Session[]
|
||||||
|
calendars Calendar[]
|
||||||
|
emailCredentials EmailCredentials?
|
||||||
|
}
|
||||||
|
|
||||||
|
model EmailCredentials {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
userId String @unique
|
||||||
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
email String
|
||||||
|
password String
|
||||||
|
host String
|
||||||
|
port Int
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user