From b4067c7685241e9c4d33f9ecf881cda880c7583a Mon Sep 17 00:00:00 2001 From: Arnaud Nelissen Date: Thu, 25 Jun 2026 08:41:56 +0200 Subject: [PATCH] fix(duplicate-day): extract userId before closure to satisfy TS strict null check session.user is narrowed inside the early-return guard but TypeScript does not carry that narrowing into the Prisma transaction callback. Extract to a const immediately after the guard. Co-Authored-By: Claude Sonnet 4.6 --- src/app/api/events/duplicate-day/route.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/api/events/duplicate-day/route.ts b/src/app/api/events/duplicate-day/route.ts index b7c6e91..8015e4c 100644 --- a/src/app/api/events/duplicate-day/route.ts +++ b/src/app/api/events/duplicate-day/route.ts @@ -5,6 +5,7 @@ import { prisma } from "@/lib/prisma"; export async function POST(req: Request) { const session = await auth(); if (!session?.user?.id) return NextResponse.json({ error: "Non autorisé" }, { status: 401 }); + const userId = session.user.id; const { babyId, sourceDate, targetDate } = await req.json(); @@ -49,7 +50,7 @@ export async function POST(req: Request) { prisma.event.create({ data: { babyId, - userId: session.user.id, + userId, type: ev.type, startedAt: new Date(ev.startedAt.getTime() + offsetMs), endedAt: ev.endedAt ? new Date(ev.endedAt.getTime() + offsetMs) : null,