Back to projects

BookNook

A small online library where readers share and borrow books

booknook-tarek.vercel.app

Screenshot of BookNook

About the project

A small online library where readers share their own books, borrow each other's for a week, and return them when they're done. I built both sides on my own: a Next.js client and a separate Express API with MongoDB. Each book tracks its available copies, so borrowing lowers the count, returning raises it, and the Borrow button turns into Not Available when none are left.

Key features

  • All Books with category filters, and the six newest arrivals on the home page
  • Email and Google sign-in, with private pages that bring you back after login
  • Adding books with a cover upload, then editing or deleting them from My Books
  • Borrowing for 7 days, with live copy counts and no double borrowing
  • My Borrows with return dates, an overdue tag and a Return button

Challenges I faced

  1. 1

    Two readers could press Borrow on the last copy at the same moment. The server lowers the count with one atomic update that only matches while copies are above zero, so exactly one of them gets the book and the other sees a clear message.

  2. 2

    Login lives in the Next.js app, but the separate Express API has to trust it too. BetterAuth issues a JSON Web Token and the API verifies it against the app's public keys with jose, so the two services never share a secret.

  3. 3

    The Book Details page loads on the server, where the browser's fetch helper can't get a token. I wrote a separate server-side helper that takes the token from the session and sends expired sessions back to login with the same page as the redirect.

  4. 4

    Private pages are guarded twice. The proxy redirects signed-out visitors before the page loads and remembers where they were going, and the API still checks the token on every protected route, so only the owner can edit or delete a book.

  5. 5

    The client and the API deploy separately, so the server's CORS rules had to allow both the live site and local development.

Future plans

  • Search by title and author alongside the category filters.
  • Ratings and reviews on each book.
  • A waitlist that tells you when a book you want is back on the shelf.
  • Letting readers extend a borrow instead of returning it.