Refactor code structure for improved readability and maintainability; removed redundant code blocks and optimized function calls.
CI/CD / test-and-build (push) Waiting to run
CI/CD / deploy (push) Blocked by required conditions

This commit is contained in:
Najjar\NajjarV02
2026-05-20 18:03:42 +04:00
parent bfe589be27
commit 729ab71c2c
65 changed files with 217 additions and 216 deletions
@@ -11,7 +11,7 @@ Add password authentication to the admin dashboard, enable full CRUD for persona
- Create `prisma/schema.prisma` with SQLite provider
- Models: `AdminUser` (id, username, passwordHash, createdAt), `AppSettings` (key, value)
- Run `npx prisma db push` to create the database
- Create `src/lib/prisma.ts` — singleton Prisma client
- Create `src/lib/prisma.ts` singleton Prisma client
2. **Create seed script** `prisma/seed.ts`
- Creates default admin user with bcrypt-hashed password
@@ -19,10 +19,10 @@ Add password authentication to the admin dashboard, enable full CRUD for persona
- Run with `npx prisma db seed`
3. **Create admin auth API routes**
- `src/app/api/admin/login/route.ts` — POST, accepts `{ username, password }`, verifies bcrypt hash from DB, returns JWT in httpOnly cookie (JWT secret from DB)
- `src/app/api/admin/verify/route.ts` — GET, checks JWT cookie validity
- `src/app/api/admin/logout/route.ts` — POST, clears auth cookie
- `src/app/api/admin/change-password/route.ts` — POST, accepts `{ currentPassword, newPassword }`, updates hash in DB
- `src/app/api/admin/login/route.ts` POST, accepts `{ username, password }`, verifies bcrypt hash from DB, returns JWT in httpOnly cookie (JWT secret from DB)
- `src/app/api/admin/verify/route.ts` GET, checks JWT cookie validity
- `src/app/api/admin/logout/route.ts` POST, clears auth cookie
- `src/app/api/admin/change-password/route.ts` POST, accepts `{ currentPassword, newPassword }`, updates hash in DB
4. **Create admin middleware** `src/middleware.ts`
- Protects all `/admin/*` routes (except `/admin/login/`)
@@ -34,7 +34,7 @@ Add password authentication to the admin dashboard, enable full CRUD for persona
- Calls login API, redirects to `/admin/` on success
- Shows error on wrong credentials
6. **Add JWT_SECRET to .env.local** (only this one — password is in DB)
6. **Add JWT_SECRET to .env.local** (only this one password is in DB)
- Alternative: store JWT secret in DB and load at startup into a module-level cache
### Dependencies to install
@@ -43,12 +43,12 @@ Add password authentication to the admin dashboard, enable full CRUD for persona
## Phase 2: Full CRUD for Pricing Items + Personas
### Steps (depends on Phase 1)
6. **Add/Remove pricing items in admin** — Update `src/app/admin/page.tsx`
6. **Add/Remove pricing items in admin** Update `src/app/admin/page.tsx`
- "Add Item" button with fields: id (auto-slug from label), label, price
- Delete button per row (with confirmation)
- Update `usePricingStore` to support `addItem()` and `removeItem()` actions
7. **Persona management section** — New section in admin page
7. **Persona management section** New section in admin page
- List current personas with edit capability (label, description, colors)
- Add new persona form
- Delete persona button
@@ -58,7 +58,7 @@ Add password authentication to the admin dashboard, enable full CRUD for persona
## Phase 3: Additional Admin Features
### Steps (parallel with Phase 2)
8. **Orders dashboard section** — New section in admin page
8. **Orders dashboard section** New section in admin page
- Show orders from Stripe API (list recent payments)
- Display: order ID, customer email, amount, status, date
- New API route `src/app/api/admin/orders/route.ts` to fetch from Stripe
@@ -77,18 +77,18 @@ Add password authentication to the admin dashboard, enable full CRUD for persona
11. **Logout button** in admin header
## Relevant Files
- `src/app/admin/page.tsx` — Main admin dashboard (add CRUD UI, analytics)
- `src/app/admin/login/page.tsx` — New login page
- `src/app/api/admin/login/route.ts` — New auth API
- `src/app/api/admin/verify/route.ts` — New verify API
- `src/app/api/admin/orders/route.ts` — New orders API
- `src/middleware.ts` — New, protects admin routes
- `src/lib/prisma.ts` — New, Prisma client singleton
- `prisma/schema.prisma` — New, database schema (AdminUser, AppSettings)
- `prisma/seed.ts` — New, seeds default admin user
- `src/store/usePricingStore.ts` — Add `addItem()`, `removeItem()` actions
- `src/components/ConfigPanel.tsx` — Persona options currently hardcoded (PERSONA_OPTIONS const)
- `.env.local` — Add ADMIN_PASSWORD, ADMIN_JWT_SECRET
- `src/app/admin/page.tsx` Main admin dashboard (add CRUD UI, analytics)
- `src/app/admin/login/page.tsx` New login page
- `src/app/api/admin/login/route.ts` New auth API
- `src/app/api/admin/verify/route.ts` New verify API
- `src/app/api/admin/orders/route.ts` New orders API
- `src/middleware.ts` New, protects admin routes
- `src/lib/prisma.ts` New, Prisma client singleton
- `prisma/schema.prisma` New, database schema (AdminUser, AppSettings)
- `prisma/seed.ts` New, seeds default admin user
- `src/store/usePricingStore.ts` Add `addItem()`, `removeItem()` actions
- `src/components/ConfigPanel.tsx` Persona options currently hardcoded (PERSONA_OPTIONS const)
- `.env.local` Add ADMIN_PASSWORD, ADMIN_JWT_SECRET
## Verification
1. Visit `/admin/` without login → redirected to `/admin/login/`
@@ -102,13 +102,13 @@ Add password authentication to the admin dashboard, enable full CRUD for persona
9. Run `npx vitest run` → all existing tests pass
## Decisions
- **Database: Prisma + SQLite** — file-based, no external server needed, real ORM
- **Database: Prisma + SQLite** file-based, no external server needed, real ORM
- Admin password stored as bcrypt hash in DB (not in env vars)
- JWT secret stored in AppSettings table in DB
- JWT in httpOnly cookie — secure, no localStorage tokens
- jose library for JWT — lightweight, edge-compatible (works in Next.js middleware)
- Personas need to move from hardcoded array to store-driven — breaking change in ConfigPanel
- Stripe orders fetched via Stripe API directly — no local DB needed for orders
- JWT in httpOnly cookie secure, no localStorage tokens
- jose library for JWT lightweight, edge-compatible (works in Next.js middleware)
- Personas need to move from hardcoded array to store-driven breaking change in ConfigPanel
- Stripe orders fetched via Stripe API directly no local DB needed for orders
## Further Considerations
1. **Persona storage**: Currently hardcoded in ConfigPanel. Moving to a store means ConfigPanel reads from store dynamically. This is required for admin CRUD to work. **Recommended: create persona store with localStorage persistence (same pattern as pricing store)**