- 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.
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { createError } from "h3";
|
|
|
|
import { requireAuth0User } from "../../utils/auth0";
|
|
import { getSupabaseServiceClient } from "../../utils/supabase";
|
|
|
|
type DesignRecord = {
|
|
id: string;
|
|
user_id: string;
|
|
name: string;
|
|
template_id: string;
|
|
preview_url: string | null;
|
|
preview_path: string | null;
|
|
design_json: unknown;
|
|
notes?: string | null;
|
|
created_at: string | null;
|
|
updated_at: string | null;
|
|
};
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const user = await requireAuth0User(event);
|
|
const supabase = getSupabaseServiceClient();
|
|
const id = event.context.params?.id;
|
|
|
|
if (!id) {
|
|
throw createError({ statusCode: 400, statusMessage: "Design id is required." });
|
|
}
|
|
|
|
const response = await supabase
|
|
.from("designs")
|
|
.select("id, user_id, name, template_id, preview_url, preview_path, design_json, notes, created_at, updated_at")
|
|
.eq("id", id)
|
|
.eq("user_id", user.sub)
|
|
.maybeSingle();
|
|
|
|
if (response.error) {
|
|
throw createError({
|
|
statusCode: 500,
|
|
statusMessage: `Failed to load design: ${response.error.message}`,
|
|
});
|
|
}
|
|
|
|
if (!response.data) {
|
|
throw createError({ statusCode: 404, statusMessage: "Design not found." });
|
|
}
|
|
|
|
return response.data as DesignRecord;
|
|
});
|