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:
@@ -20,6 +20,7 @@ export interface ExportedDesign {
|
||||
productionBlob: Blob;
|
||||
templateId: string;
|
||||
createdAt: string;
|
||||
canvasJson: FabricCanvasJSON;
|
||||
}
|
||||
|
||||
const DISPLAY_SIZE = 720;
|
||||
@@ -63,6 +64,7 @@ type FabricCircle = FabricNamespace.Circle;
|
||||
type FabricRect = FabricNamespace.Rect;
|
||||
type FabricTextbox = FabricNamespace.Textbox;
|
||||
type FabricObject = FabricNamespace.Object;
|
||||
type FabricCanvasJSON = ReturnType<FabricCanvas["toJSON"]>;
|
||||
|
||||
type CanvasReadyPayload = {
|
||||
canvas: FabricCanvas;
|
||||
@@ -638,6 +640,8 @@ export const useSlipmatDesigner = () => {
|
||||
}
|
||||
productionObjectUrl.value = URL.createObjectURL(productionDataBlob);
|
||||
|
||||
const canvasJson = currentCanvas.toJSON() as FabricCanvasJSON;
|
||||
|
||||
return {
|
||||
previewUrl: previewDataUrl,
|
||||
previewBlob: previewDataBlob,
|
||||
@@ -645,12 +649,30 @@ export const useSlipmatDesigner = () => {
|
||||
productionBlob: productionDataBlob,
|
||||
templateId: selectedTemplate.value.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
canvasJson,
|
||||
};
|
||||
} finally {
|
||||
isExporting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const loadDesignFromJson = async (designJson: FabricCanvasJSON) => {
|
||||
const fabric = fabricApi.value;
|
||||
const currentCanvas = canvas.value;
|
||||
if (!fabric || !currentCanvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
currentCanvas.loadFromJSON(designJson, () => {
|
||||
currentCanvas.renderAll();
|
||||
maintainStaticLayerOrder();
|
||||
schedulePreviewRefresh();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const downloadPreview = async () => {
|
||||
if (!previewUrl.value) {
|
||||
await refreshPreview();
|
||||
@@ -717,6 +739,7 @@ export const useSlipmatDesigner = () => {
|
||||
resetZoom,
|
||||
clearDesign,
|
||||
exportDesign,
|
||||
loadDesignFromJson,
|
||||
downloadPreview,
|
||||
downloadProduction,
|
||||
refreshPreview,
|
||||
|
||||
Reference in New Issue
Block a user