diff --git a/app/api/courrier/route.ts b/app/api/courrier/route.ts index e11613b..32a41b3 100644 --- a/app/api/courrier/route.ts +++ b/app/api/courrier/route.ts @@ -23,15 +23,16 @@ const CACHE_TTL = 60 * 1000; const emailListCache: Record = {}; export async function GET(request: Request) { + // Authenticate user (declare outside try to access in catch) + const session = await getServerSession(authOptions); + if (!session || !session.user?.id) { + return NextResponse.json( + { error: "Not authenticated" }, + { status: 401 } + ); + } + try { - // Authenticate user - const session = await getServerSession(authOptions); - if (!session || !session.user?.id) { - return NextResponse.json( - { error: "Not authenticated" }, - { status: 401 } - ); - } // Extract query parameters const { searchParams } = new URL(request.url);