diff --git a/src/components/ui/sidebar.tsx b/src/components/ui/sidebar.tsx index 502bfcca..37ea9ff6 100644 --- a/src/components/ui/sidebar.tsx +++ b/src/components/ui/sidebar.tsx @@ -615,6 +615,3 @@ export { SidebarSeparator, SidebarTrigger, }; - -// Re-export useSidebar from the hooks file for backwards compatibility -export { useSidebar } from "@/hooks/useSidebar"; diff --git a/supabase/functions/upload-image/index.ts b/supabase/functions/upload-image/index.ts index a06822bb..519a393d 100644 --- a/supabase/functions/upload-image/index.ts +++ b/supabase/functions/upload-image/index.ts @@ -41,6 +41,20 @@ const getCorsHeaders = (requestOrigin: string | null) => ({ 'Access-Control-Allow-Credentials': 'true', }); +// Helper to create authenticated Supabase client +const createAuthenticatedSupabaseClient = (authHeader: string) => { + const supabaseUrl = Deno.env.get('SUPABASE_URL') + const supabaseAnonKey = Deno.env.get('SUPABASE_ANON_KEY') + + if (!supabaseUrl || !supabaseAnonKey) { + throw new Error('Missing Supabase environment variables') + } + + return createClient(supabaseUrl, supabaseAnonKey, { + global: { headers: { Authorization: authHeader } } + }) +} + serve(async (req) => { const requestOrigin = req.headers.get('origin'); const corsHeaders = getCorsHeaders(requestOrigin); @@ -76,11 +90,7 @@ serve(async (req) => { } // Verify JWT token - const supabaseUrl = Deno.env.get('SUPABASE_URL')! - const supabaseAnonKey = Deno.env.get('SUPABASE_ANON_KEY')! - const supabase = createClient(supabaseUrl, supabaseAnonKey, { - global: { headers: { Authorization: authHeader } } - }) + const supabase = createAuthenticatedSupabaseClient(authHeader) const { data: { user }, error: authError } = await supabase.auth.getUser() if (authError || !user) { @@ -262,11 +272,7 @@ serve(async (req) => { } // Verify JWT token - const supabaseUrl = Deno.env.get('SUPABASE_URL')! - const supabaseAnonKey = Deno.env.get('SUPABASE_ANON_KEY')! - const supabase = createClient(supabaseUrl, supabaseAnonKey, { - global: { headers: { Authorization: authHeader } } - }) + const supabase = createAuthenticatedSupabaseClient(authHeader) const { data: { user }, error: authError } = await supabase.auth.getUser() if (authError || !user) { @@ -438,11 +444,7 @@ serve(async (req) => { } // Verify JWT token - const supabaseUrl = Deno.env.get('SUPABASE_URL')! - const supabaseAnonKey = Deno.env.get('SUPABASE_ANON_KEY')! - const supabase = createClient(supabaseUrl, supabaseAnonKey, { - global: { headers: { Authorization: authHeader } } - }) + const supabase = createAuthenticatedSupabaseClient(authHeader) const { data: { user }, error: authError } = await supabase.auth.getUser() if (authError || !user) {