From 8ad048204e104089ae64950411c40cfa75f6904b Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 23:14:13 +0100 Subject: [PATCH] Fondation --- app/api/courrier/account/route.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/api/courrier/account/route.ts b/app/api/courrier/account/route.ts index 619d837..27a9130 100644 --- a/app/api/courrier/account/route.ts +++ b/app/api/courrier/account/route.ts @@ -104,15 +104,16 @@ async function ensureUserExists(session: any): Promise { } export async function POST(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 { - // Authenticate user - const session = await getServerSession(authOptions); - if (!session?.user?.id) { - return NextResponse.json( - { error: 'Unauthorized' }, - { status: 401 } - ); - } // Ensure user exists in database (create if missing) // This handles cases where the database was reset but users still exist in Keycloak