This project now includes Firebase Firestore for data persistence and management.
Complete CRUD operations for products:
- ✅
getFirestoreProducts()- Fetch all products or by category - ✅
getFirestoreProduct(id)- Get single product by ID - ✅
addFirestoreProduct()- Add new product - ✅
updateFirestoreProduct()- Update existing product - ✅
deleteFirestoreProduct()- Delete product - ✅
getFirestoreProductsByCategory()- Filter products by category - ✅
getFeaturedProducts()- Get featured products - ✅
searchFirestoreProducts()- Search products by title - ✅
seedFirestoreProducts()- Seed database from external API
useFirestoreProducts(category?)- Fetch products with loading/error statesuseFirestoreProduct(id)- Fetch single productuseSearchFirestoreProducts()- Search with debouncinguseFirestoreProductsByCategory()- Category-filtered products
Protected admin page at /admin/products with:
- 📊 View all products in Firestore
- ⬇️ Seed products from FakeStore API
- 🗑️ Delete products
- 📝 Product management interface
- 📈 Product count and statistics
seedProductsFromAPI()- Import products from FakeStore APIcheckFirestoreProducts()- Check if database has products
products/
{productId}/
- title: string
- price: number
- description: string
- category: string
- image: string
- rating: { rate: number, count: number }
- createdAt: Timestamp
- updatedAt: Timestamp
- stock: number (default: 100)
- featured: boolean (default: false)
users/- User profilescarts/- Shopping cartswishlists/- User wishlistsorders/- Order history
Visit /admin/products and click "Seed Products from API" to import all products from FakeStore API into your Firestore database.
To use Firestore instead of FakeStore API, update your components to use the Firestore hooks:
// Before (using API)
import { useProducts } from '@/hooks/useProducts';
// After (using Firestore)
import { useFirestoreProducts } from '@/hooks/useFirestoreProducts';
// In component
const { products, loading, error } = useFirestoreProducts();- Navigate to
/admin/productsto manage your Firestore products - Requires authentication (protected route)
| Operation | FakeStore API | Firestore |
|---|---|---|
| Fetch Products | api.getProducts() |
getFirestoreProducts() |
| Fetch by Category | api.getProducts(category) |
getFirestoreProductsByCategory() |
| Single Product | api.getProduct(id) |
getFirestoreProduct(id) |
| Search | ❌ Not available | ✅ searchFirestoreProducts() |
| Add Product | ❌ Read-only | ✅ addFirestoreProduct() |
| Update Product | ❌ Read-only | ✅ updateFirestoreProduct() |
| Delete Product | ❌ Read-only | ✅ deleteFirestoreProduct() |
- Real-time Updates - Changes sync instantly
- Offline Support - Works offline with local cache
- Full CRUD - Add, edit, delete products
- Custom Fields - Add stock, featured flags, etc.
- Scalability - Scales automatically with usage
- Security - Firebase Security Rules protection
You can gradually migrate from FakeStore API to Firestore:
- ✅ Keep using FakeStore API (default)
- ✅ Seed Firestore with products
- ✅ Test Firestore with admin panel
- ✅ Switch components to Firestore hooks when ready
Both systems work side-by-side!
Add these to Firebase Console → Firestore Database → Rules:
``` rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { // Products - read for all, write for authenticated users match /products/{productId} { allow read: if true; allow write: if request.auth != null; } // Other collections... } } ```
- Add product image upload to Firebase Storage
- Implement real-time product updates
- Add inventory tracking
- Create product categories collection
- Add product reviews and ratings