- 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.
35 lines
967 B
TypeScript
35 lines
967 B
TypeScript
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]!;
|
|
};
|