diff --git a/app/api/courrier/[id]/route.ts b/app/api/courrier/[id]/route.ts index 0d2707a3..be8ab17c 100644 --- a/app/api/courrier/[id]/route.ts +++ b/app/api/courrier/[id]/route.ts @@ -14,7 +14,7 @@ import { getCachedEmailContent, invalidateEmailContentCache } from '@/lib/redis' export async function GET( request: Request, - { params }: { params: { id: string } } + context: { params: { id: string } } ) { try { const session = await getServerSession(authOptions); @@ -25,7 +25,9 @@ export async function GET( ); } - const { id } = params; + // Await params as per Next.js requirements + const { params } = context; + const id = params?.id; if (!id) { return NextResponse.json( { error: "Missing email ID" }, @@ -39,7 +41,7 @@ export async function GET( try { // Try to get email from Redis cache first - const cachedEmail = await getCachedEmailContent(session.user.id, id); + const cachedEmail = await getCachedEmailContent(session.user.id, accountId || 'default', id); if (cachedEmail) { console.log(`Using cached email content for ${session.user.id}:${id}`); return NextResponse.json(cachedEmail); @@ -48,7 +50,7 @@ export async function GET( console.log(`Cache miss for email content ${session.user.id}:${id}, fetching from IMAP`); // Use the email service to fetch the email content - const email = await getEmailContent(session.user.id, id, folder, accountId); + const email = await getEmailContent(session.user.id, id, folder, accountId || undefined); // Return the complete email object return NextResponse.json(email); @@ -71,7 +73,7 @@ export async function GET( // Add a route to mark email as read export async function POST( request: Request, - { params }: { params: { id: string } } + context: { params: { id: string } } ) { try { const session = await getServerSession(authOptions); @@ -82,7 +84,9 @@ export async function POST( ); } - const { id } = params; + // Await params as per Next.js requirements + const { params } = context; + const id = params?.id; if (!id) { return NextResponse.json( { error: "Missing email ID" }, @@ -101,6 +105,7 @@ export async function POST( const { searchParams } = new URL(request.url); const folder = searchParams.get("folder") || "INBOX"; + const accountId = searchParams.get("accountId"); // Use the email service to mark the email const success = await markEmailReadStatus( @@ -118,7 +123,7 @@ export async function POST( } // Invalidate cache for this email - await invalidateEmailContentCache(session.user.id, id); + await invalidateEmailContentCache(session.user.id, accountId || 'default', id); return NextResponse.json({ success: true }); } catch (error: any) {