diff --git a/app/api/courrier/account/route.ts b/app/api/courrier/account/route.ts index 27a9130..54d5c6c 100644 --- a/app/api/courrier/account/route.ts +++ b/app/api/courrier/account/route.ts @@ -264,11 +264,13 @@ export async function POST(request: Request) { } export async function DELETE(request: Request) { + // Authenticate user (declare outside try to access in catch) + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + } + try { - const session = await getServerSession(authOptions); - if (!session?.user?.id) { - return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); - } const { searchParams } = new URL(request.url); const accountId = searchParams.get('accountId'); if (!accountId) {