A comprehensive bookshop e-commerce platform built with Next.js, Supabase, and M-Pesa payment integration. Features include user authentication, shopping cart, admin dashboard, and dark/light theme support.
- 🔐 User Authentication - Sign up, login, password reset
- 📖 Book Catalog - Browse books by category, search, and filter
- 🛒 Shopping Cart - Add/remove items, quantity management
- 💳 Checkout & Payment - M-Pesa integration via Quikk API
- 📱 Responsive Design - Mobile-first approach
- 🌙 Dark/Light Theme - Toggle between themes
- 👤 User Profile - Order history and account management
- 📊 Dashboard - Sales analytics and overview
- 💰 Payment Management - M-Pesa transaction monitoring
- 📦 Order Management - Track and update order statuses
- 📚 Book Management - Add, edit, and manage inventory
- Frontend: Next.js 14, React, TypeScript, Tailwind CSS
- Backend: Next.js API Routes, Server Actions
- Database: Supabase (PostgreSQL)
- Authentication: Supabase Auth
- Payments: Quikk API (M-Pesa)
- UI Components: shadcn/ui
- Theme: next-themes
- Node.js 18+ and npm/yarn
- Supabase account
- Quikk API account (for M-Pesa payments)
```bash git clone cd bookshop-project npm install ```
- Go to supabase.com
- Create a new project
- Note your project URL and anon key
Create a .env.local file in the root directory:
```env
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
QUIKK_API_BASE_URL=https://api.quikk.dev QUIKK_API_KEY=your_quikk_api_key NEXT_PUBLIC_BASE_URL=http://localhost:3000 ```
Run the SQL scripts in order in your Supabase SQL editor:
```bash
scripts/001_create_database_schema.sql
scripts/002_create_admin_user.sql
scripts/003_create_cart_table.sql
scripts/004_populate_authors.sql scripts/005_populate_categories.sql scripts/006_populate_books.sql scripts/007_create_sample_orders.sql scripts/008_create_sample_reviews.sql ```
```bash
npm install -g supabase
supabase login supabase link --project-ref your-project-ref
supabase db push ```
- Go to Supabase Dashboard → Authentication → Settings
- Enable "Enable email confirmations" (optional)
- Configure email templates if needed
The database scripts automatically set up RLS policies. Verify they're enabled:
- Go to Supabase Dashboard → Authentication → Policies
- Ensure all tables have appropriate policies
To create an admin user:
- Sign up normally through the app
- Find your user ID in Supabase Dashboard → Authentication → Users
- Run this SQL in Supabase SQL editor:
```sql -- Replace 'your-user-id' with actual user ID UPDATE customers SET is_admin = true WHERE auth_user_id = 'your-user-id'; ```
Or use the provided script: ```sql -- Update the email in scripts/002_create_admin_user.sql -- Then run the script ```
```bash npm run dev ```
Visit http://localhost:3000
```bash npm run build npm start ```
- Browse Books: Visit
/booksor/categories - Sign Up: Create account at
/auth/register - Add to Cart: Click "Add to Cart" on any book
- Checkout: Go to
/cart→ "Proceed to Checkout" - Payment: Complete M-Pesa payment process
- Login: Use admin credentials
- Dashboard: Access
/adminfor overview - Payments: Monitor transactions at
/admin/payments - Orders: Manage orders at
/admin/orders
-
Get Quikk API Credentials:
- Contact dean@quikk.dev for API access
- Add credentials to environment variables
-
Test Payments:
- Use test phone numbers in development
- Monitor payment status in admin dashboard
The app supports automatic theme detection and manual toggle:
- System preference detection
- Persistent theme selection
- Smooth transitions between themes
customers- User profiles and admin flagsauthors- Book authors informationcategories- Book categoriesbooks- Book catalog with inventoryorders- Customer ordersorder_items- Order line itemspayments- Payment transactionsreviews- Book reviews and ratingscart_items- Shopping cart persistence
- Books → Authors (many-to-one)
- Books → Categories (many-to-one)
- Orders → Customers (many-to-one)
- Order Items → Books (many-to-one)
- Payments → Orders (one-to-one)
- Row Level Security (RLS) on all tables
- Authentication middleware for protected routes
- Admin role verification for admin pages
- Input validation on all forms
- SQL injection protection via Supabase client
- Ensure CartProvider wraps the entire app in
layout.tsx
- Verify environment variables are correct
- Check Supabase project status
- Ensure RLS policies are properly configured
- Verify user has
is_admin = truein customers table - Check authentication status
- Ensure middleware is properly configured
- Verify Quikk API credentials
- Check phone number format (+254...)
- Monitor network connectivity
- Review payment logs in admin dashboard
Add debug logging by uncommenting console.log statements:
```typescript console.log("[v0] Debug info:", data); ```
POST /api/auth/login- User loginPOST /api/auth/register- User registrationPOST /api/auth/logout- User logout
POST /api/payments/mpesa- Initiate M-Pesa paymentGET /api/payments/status- Check payment statusPOST /api/payments/callback- M-Pesa callback handler
GET /api/books- Fetch books with filteringPOST /api/cart- Add item to cartPUT /api/cart- Update cart itemDELETE /api/cart- Remove cart item
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For technical support:
- Check the troubleshooting section above
- Review Supabase documentation
- Contact the development team
Happy Reading! 📖✨