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 address

Update user address

OK, so we have our form. And it's getting submitted to this on submit. We have access to the values. Now we want to have an action to update the user address to the values in the form. So let's go to our lib actions and user actions file. And at the bottom here, we're going to go ahead and add a new function. So we'll say this is going to update the user's address. So let's export an asynchronous function and call it update user address. Now, this is going to take in what we're going to call data. And it's going to have the type of shipping address, which is brought in up top from the types file. And then let's have a try catch. And in the catch, we want to do what we've been doing, which is return an object with the success, which is going to be false. And we want the message. Message is going to be the error, but we want to wrap it in our format error function that we created, which should have already been brought in up top. And then in the try, let's get the session. And we do…

Contents