# User is possibly bull (9-Updating Data - lecture)

**URL:** <https://forum.codewithmosh.com/t/user-is-possibly-bull-9-updating-data-lecture/23772>\
**Category:** Next.js\
**Created:** [November 21, 2023, 3:39am UTC](https://forum.codewithmosh.com/t/user-is-possibly-bull-9-updating-data-lecture/23772 "2023-11-21T03:39:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bnazeem](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bnazeem](https://forum.codewithmosh.com/u/bnazeem)\
**Post date:** [November 21, 2023, 3:39am UTC](https://forum.codewithmosh.com/t/user-is-possibly-bull-9-updating-data-lecture/23772/1 "2023-11-21T03:39:06Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/3/32d0ca5754a4d6fbb24d618953eebc7b9eabdf32.png)

I am getting this error message : ‘user’ is possibly 'null" for PUT request:

const updatedUser = await prisma.user.update({  
where: { id: user.id },  
data: {  
name: body.name,  
email: body.email,  
},  
});

Here is my code:

export async function PUT(  
request: NextRequest,  
{ params }: { params: { id: string } }  
) {

const body = await request.json();

const validation = schema.safeParse(body);

if (!validation.success)  
return NextResponse.json(validation.error.errors, { status: 400 });

const user = await prisma.user.findUnique({  
where: { id: parseInt(params.id) },  
});

if (user)  
return NextResponse.json({ error: “User not found” }, { status: 404 });

const updatedUser = await prisma.user.update({  
where: { id: user.id },  
data: {  
name: body.name,  
email: body.email,  
},  
});

return NextResponse.json(updatedUser);  
}

---

<div class="post-metadata">

**Author:** ![bnazeem](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bnazeem](https://forum.codewithmosh.com/u/bnazeem)\
**Post date:** [November 21, 2023, 3:44am UTC](https://forum.codewithmosh.com/t/user-is-possibly-bull-9-updating-data-lecture/23772/2 "2023-11-21T03:44:48Z")

</div>

My bad , I found the error, I should check for → if (!user).

Thanks

---

<div class="post-metadata">

**Author:** ![JerryHobby](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jerryhobby/32/5370_2.png) [@JerryHobby](https://forum.codewithmosh.com/u/JerryHobby)\
**Post date:** [November 22, 2023, 7:21pm UTC](https://forum.codewithmosh.com/t/user-is-possibly-bull-9-updating-data-lecture/23772/3 "2023-11-22T19:21:29Z")

</div>

First off – great job finding the bug.

Secondly – Thank you for not deleting the topic. It might help others. 🙂
