Build the Library
15 min read
Delete Books Safely
Delete Books Safely
Task
Add safe Book deletion before storage files exist.
Route
Create:
DELETE /api/books/:id
First verify ownership:
const result = await prisma.book.deleteMany({
where: {
id: bookId,
userId: user.id,
},
});
if (result.count === 0) {
return Response.json({ error: "Book not found" }, { status: 404 });
}
Do not use a browser confirm().
Use the project’s custom delete dialog and require an explicit confirmation.
UI
After deletion:
- close the dialog
- remove or refresh the book
- show a bottom-right success toast
Storage cleanup is intentionally deferred until Module 5, when each Book can have an associated object-storage key.
Test
Delete a book and reload the Library. Confirm it is gone.
Cancel the custom dialog and confirm nothing is deleted.
Checkpoint
Book deletion works through a deliberate UI confirmation and an authenticated server mutation.