© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4mo ago•
10 replies
Floppy Disk

.insert().select() doesnt work due to rls

Insert alone works
return await supabase
    .from("question")
    .insert({
      ...body,
      survey_id,
      question_bank_ref_id,
      selected_configuration,
      field_type_context_stack,
      survey_bank_question_bank_ref_id,
    })
    .select()
    .maybeSingle()
    .throwOnError()
    .then(res => res.data);
return await supabase
    .from("question")
    .insert({
      ...body,
      survey_id,
      question_bank_ref_id,
      selected_configuration,
      field_type_context_stack,
      survey_bank_question_bank_ref_id,
    })
    .select()
    .maybeSingle()
    .throwOnError()
    .then(res => res.data);

Select RLS:
DROP POLICY IF EXISTS question_own_select ON public.question;
CREATE POLICY "question_own_select" ON public.question
  FOR SELECT
  TO authenticated
  USING (
    (
      public.question.user_id = (select auth.uid)
    )
  );
DROP POLICY IF EXISTS question_project_or_org_member_select ON public.question;
CREATE POLICY "question_project_or_org_member_select" ON public.question
  FOR SELECT
  TO authenticated
  USING (
    (
      EXISTS (
        SELECT 1
        FROM public.project_members pm
        WHERE pm.project_id = public.get_question_project_id(id)
          AND pm.user_id = (SELECT auth.uid())
      )
    )
    OR
    (
      EXISTS (
        SELECT 1
        FROM public.organisation_members om
        WHERE om.organisation_id = public.get_question_organisation_id(id)
          AND om.user_id = (SELECT auth.uid())
      )
    )
  );
DROP POLICY IF EXISTS question_own_select ON public.question;
CREATE POLICY "question_own_select" ON public.question
  FOR SELECT
  TO authenticated
  USING (
    (
      public.question.user_id = (select auth.uid)
    )
  );
DROP POLICY IF EXISTS question_project_or_org_member_select ON public.question;
CREATE POLICY "question_project_or_org_member_select" ON public.question
  FOR SELECT
  TO authenticated
  USING (
    (
      EXISTS (
        SELECT 1
        FROM public.project_members pm
        WHERE pm.project_id = public.get_question_project_id(id)
          AND pm.user_id = (SELECT auth.uid())
      )
    )
    OR
    (
      EXISTS (
        SELECT 1
        FROM public.organisation_members om
        WHERE om.organisation_id = public.get_question_organisation_id(id)
          AND om.user_id = (SELECT auth.uid())
      )
    )
  );


user_id
user_id
in table
questions
questions
is set with default value
auth.uid()
auth.uid()
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Failing to insert due to policy?
SupabaseSSupabase / help-and-questions
4y ago
Unable to Insert Data into Supabase users Table Due to Row Level Security (RLS)
SupabaseSSupabase / help-and-questions
7mo ago
RLS - Help with Insert Policy
SupabaseSSupabase / help-and-questions
4y ago
RLS policy blocking Insert from Debug
SupabaseSSupabase / help-and-questions
5mo ago