From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Update user action

Update user action

We now need the update user form to actually work. So let's create the action that we're going to submit to. So we'll go to lib actions and then user actions. And we'll go down to the bottom here. And let's say this is going to update a user. So we're going to export. And let's say async function. We'll call it update user. Now, as far as what this is going to take in, it's going to be the user. And we can set it to the type by using z.infer. And say we want type of, and then the update user schema. And then in the function body, let's add a try catch as usual. And in the error, as usual, we're going to return success false and the message will be format error and pass in the error. Alright and then in the try we're going to go ahead and make our query so we want prisma dot user dot update and we want to update where so So let's say where the ID is equal to the user. Now, we're passing in the entire user object. So we want the user.id. And then the data that we're updating is going to…

Contents