-- Update is_admin to handle both traditional Supabase Auth and Clerk Auth
CREATE OR REPLACE FUNCTION is_admin()
RETURNS BOOLEAN AS $$
DECLARE
  v_clerk_id TEXT;
  v_supabase_id UUID;
BEGIN
  v_clerk_id := get_clerk_user_id();
  v_supabase_id := auth.uid();
  
  RETURN EXISTS (
    SELECT 1 FROM profiles 
    WHERE (
      (v_clerk_id IS NOT NULL AND clerk_user_id = v_clerk_id)
      OR 
      (v_supabase_id IS NOT NULL AND id = v_supabase_id)
    ) 
    AND role = 'admin'
  );
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
