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:
34
server/utils/supabase.ts
Normal file
34
server/utils/supabase.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { createClient, type SupabaseClient } from "@supabase/supabase-js";
|
||||
import { createError } from "h3";
|
||||
import { useRuntimeConfig } from "#imports";
|
||||
|
||||
const globalKey = Symbol.for("slipmatz.supabase.serviceClient");
|
||||
|
||||
type GlobalWithSupabase = typeof globalThis & {
|
||||
[globalKey]?: SupabaseClient;
|
||||
};
|
||||
|
||||
export const getSupabaseServiceClient = (): SupabaseClient => {
|
||||
const config = useRuntimeConfig();
|
||||
const supabaseUrl = config.public.supabase?.url;
|
||||
const serviceRoleKey = config.supabase?.serviceRoleKey;
|
||||
|
||||
if (!supabaseUrl || !serviceRoleKey) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "Supabase environment variables are not configured.",
|
||||
});
|
||||
}
|
||||
|
||||
const scope = globalThis as GlobalWithSupabase;
|
||||
if (!scope[globalKey]) {
|
||||
scope[globalKey] = createClient(supabaseUrl, serviceRoleKey, {
|
||||
auth: {
|
||||
autoRefreshToken: false,
|
||||
persistSession: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return scope[globalKey]!;
|
||||
};
|
||||
Reference in New Issue
Block a user