-
Wishlist Routes (
backend/routes/wishlistRoutes.js)- GET
/api/wishlist- Fetch user's wishlist - POST
/api/wishlist/:productId- Add product to wishlist - DELETE
/api/wishlist/:productId- Remove product from wishlist
- GET
-
User Model - Already had wishlist field (array of Product references)
-
Server - Added wishlist routes to Express app
-
Wishlist Store (
lib/store.ts)- Syncs with backend API
- Persists to localStorage
- Loads automatically when user logs in
-
Navigation (
components/navbar.tsx)- Wishlist icon with badge showing item count
- Desktop menu link to wishlist page
- Mobile dropdown menu link
-
Wishlist Page (
app/wishlist/page.tsx)- Displays all saved products
- Add to cart functionality
- Remove from wishlist
-
Products Page (
app/products/page.tsx)- Heart icon to add/remove from wishlist
- Shows filled heart for wishlisted items
-
Start the backend server:
cd backend npm run dev -
Start the frontend:
npm run dev
-
Test the feature:
- Login or register as a customer
- Go to Products page
- Click the heart icon on any product
- Check the wishlist icon in navbar (should show count)
- Click "Wishlist" in navbar or the heart icon
- View your saved products
- Products persist across sessions
If wishlist is not saving:
- Check if you're logged in - Wishlist requires authentication
- Check browser console for errors
- Check backend logs for API errors
- Verify MongoDB connection is working
- Check that DISABLE_AUTH is set correctly in
.env
Test with curl or Postman:
# Get wishlist (requires auth token)
curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:5000/api/wishlist
# Add to wishlist
curl -X POST -H "Authorization: Bearer YOUR_TOKEN" http://localhost:5000/api/wishlist/PRODUCT_ID
# Remove from wishlist
curl -X DELETE -H "Authorization: Bearer YOUR_TOKEN" http://localhost:5000/api/wishlist/PRODUCT_ID