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.

Delete users

Delete users

So now that we have our users listed in the admin area, we want to delete them. So we're going to use the delete dialog, but we need an action to submit to to actually do the delete, which is going to be pretty simple. So if we go to user actions, and we go all the way down to the bottom, let's say we want to delete a user and let's export let's say export async function and and we're just going to call it DeleteUser, uppercase U, and this is going to take in the ID so that we know which one we're deleting, and that's going to be a string. And then we'll do a try catch, and in the catch, let's return success, false, and for For the message, we'll use our format error function and pass in the error. And then up here in the try, we want to make our database query. So await prisma dot, and then we're dealing with the user model, and then we want to delete from the user model. And we want to delete where the ID is equal to the ID that's passed in, so we can just Let's do that. Then we…

Contents