feat: add design persistence functionality with Auth0 and Supabase integration

- Implemented `useDesignPersistence` composable for managing design records.
- Enhanced `useSlipmatDesigner` to support loading designs from JSON.
- Created global authentication middleware for route protection.
- Added Supabase client plugin for database interactions.
- Developed API endpoints for fetching, saving, and retrieving designs.
- Introduced utility functions for Auth0 token verification and Supabase client retrieval.
- Updated Nuxt configuration to include Auth0 and Supabase environment variables.
- Added necessary dependencies for Auth0 and Supabase.
- Enhanced TypeScript configuration for improved type support.
This commit is contained in:
Frank John Begornia
2025-11-07 00:01:52 +08:00
parent e2955debb7
commit 4d91925fad
20 changed files with 1242 additions and 19 deletions

View File

@@ -7,17 +7,55 @@ Nuxt 4 single-page experience for creating custom slipmat artwork. Users pick a
- Template presets for popular vinyl diameters with bleed & safe-zone guides
- Fabric.js-powered editor: drag, scale, rotate, and stack elements inside a clipped circular canvas
- Tools for adding text, circles, rectangles, and uploading artwork
- Live preview card with instant web-resolution snapshot
- Live preview card with instant web-resolution snapshot and turntable mockup
- One-click export that produces both preview and print PNGs and offers direct downloads
- Auth0-protected workspace with Supabase-backed “Save to Library” persistence
## 🚀 Quick Start
```bash
cp .env.example .env # set Auth0 + Supabase credentials
npm install
npm run dev
```
Visit [http://localhost:3000](http://localhost:3000) to start designing.
Visit [http://localhost:3000](http://localhost:3000) to start designing. Authentication is required for every route except the Auth0 callback.
### Auth0 & Supabase configuration
1. **Auth0 application**
- Create a SPA application and note the domain, client ID, and client secret.
- Add `http://localhost:3000` to the allowed callback, logout, and web origins.
- If you plan to call custom APIs, configure an audience and scope (defaults to `openid profile email`).
2. **Supabase project**
- Create a storage bucket named `designs` (or change `SUPABASE_STORAGE_BUCKET`).
- Create a Postgres table for persisted projects:
```sql
create table public.designs (
id uuid primary key default gen_random_uuid(),
user_id text not null,
name text not null,
template_id text not null,
preview_path text not null,
preview_url text,
design_json jsonb not null,
notes text,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index designs_user_id_updated_at_idx
on public.designs (user_id, updated_at desc);
```
- Grant read/write access to the AUTH0 users via Row Level Security (example policy: `user_id = auth.jwt()->>'sub'`).
- Generate an anon key and service role key; place them in `.env` along with the project URL.
3. **Environment**
- Populate `.env` using `.env.example` as a guide.
- Restart the dev server after changes.
## 🛠️ Production Builds
@@ -37,17 +75,19 @@ Nuxt outputs the server bundle into `.output/`. You can serve it with `node .out
- _Web preview_: 1024×1024 PNG suitable for the storefront and checkout review.
- _Print-ready PNG_: Exact template resolution (e.g. 3600×3600 for a 12" slipmat at 300DPI) for production.
High-res exports remain client-side (no upload yet). Wire the `exportDesign` / `productionBlob` values into your backend to submit orders.
Saving a project now serializes the Fabric.js canvas, uploads the preview PNG to Supabase Storage, and stores metadata within the `designs` table for quick retrieval.
## 📦 Tech Stack
- [Nuxt 4](https://nuxt.com/) + Vite
- [Fabric.js 6](http://fabricjs.com/) for canvas editing
- Tailwind CSS (via `@tailwindcss/vite`) for styling utilities
- [Auth0 Vue SDK](https://auth0.com/docs/libraries/auth0-vue) for authentication
- [Supabase](https://supabase.com/) (Postgres + Storage) for persistence
## 🧭 Next Ideas
- Persist projects (auth + cloud storage)
- Project version history and “duplicate design” shortcuts
- CMYK color profile previews & bleed handling
- 3D platter preview using Three.js
- Admin dashboard for incoming print jobs