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:
39
server/api/designs/index.get.ts
Normal file
39
server/api/designs/index.get.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { createError, getQuery } from "h3";
|
||||
|
||||
import { requireAuth0User } from "../../utils/auth0";
|
||||
import { getSupabaseServiceClient } from "../../utils/supabase";
|
||||
|
||||
type DesignSummary = {
|
||||
id: string;
|
||||
name: string;
|
||||
template_id: string;
|
||||
preview_url: string | null;
|
||||
preview_path: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
};
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const user = await requireAuth0User(event);
|
||||
const supabase = getSupabaseServiceClient();
|
||||
const query = getQuery(event);
|
||||
|
||||
const limit = query.limit ? Number.parseInt(String(query.limit), 10) : 20;
|
||||
const sanitizedLimit = Number.isFinite(limit) && limit > 0 ? Math.min(limit, 100) : 20;
|
||||
|
||||
const response = await supabase
|
||||
.from("designs")
|
||||
.select("id, name, template_id, preview_url, preview_path, created_at, updated_at")
|
||||
.eq("user_id", user.sub)
|
||||
.order("updated_at", { ascending: false })
|
||||
.limit(sanitizedLimit);
|
||||
|
||||
if (response.error) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: `Failed to fetch designs: ${response.error.message}`,
|
||||
});
|
||||
}
|
||||
|
||||
return (response.data as DesignSummary[]) ?? [];
|
||||
});
|
||||
Reference in New Issue
Block a user