CodingNic

Bookmarks, Highlights & Notes

Create and Toggle Bookmarks

Bookmarks, Highlights & Notes 18 min read

Create and Toggle Bookmarks

Create and Toggle Bookmarks

Task

Add a user-scoped Bookmark API and connect the Reader bookmark control.

Route

Create:

text
app/api/books/[bookId]/bookmarks/route.ts

Store the EPUB CFI for the bookmarked location.

Create or remove the bookmark through an authenticated mutation. Always scope it with userId and bookId.

The Reader button should toggle its active state after the mutation succeeds.

Show the existing bottom-right success toast after a successful action.

Test

At a reading position:

  1. add a bookmark
  2. reload
  3. remove the bookmark
  4. verify the database state

Try another user’s Book ID.

Checkpoint

The Reader can create and remove persistent bookmarks for the current user.