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 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user