SupabaseS
Supabase3mo ago
Ninja

need help with RLS policy

problem :
I was trying to sign up a user. After calling supabase.auth.signUp, I create a row in the business table, then in the profiles table, using auth.user.id, the business_id, and some other details. However, I encounter an issue with RLS during the business creation process.


error :
new row violates row-level security policy for table "businesses"


RLS policy:
[
  {
    "schemaname": "public",
    "tablename": "businesses",
    "policyname": "allow authenticated inserts with owner",
    "permissive": "PERMISSIVE",
    "roles": "{authenticated}",
    "cmd": "INSERT",
    "qual": null,
    "with_check": "(owner_id = ( SELECT auth.uid() AS uid))"
  },
  {
    "schemaname": "public",
    "tablename": "businesses",
    "policyname": "businesses_select",
    "permissive": "PERMISSIVE",
    "roles": "{public}",
    "cmd": "SELECT",
    "qual": "(id = ( SELECT profiles.business_id\n   FROM profiles\n  WHERE (profiles.id = auth.uid())))",
    "with_check": null
  },
  {
    "schemaname": "public",
    "tablename": "businesses",
    "policyname": "businesses_update",
    "permissive": "PERMISSIVE",
    "roles": "{public}",
    "cmd": "UPDATE",
    "qual": "(id = ( SELECT profiles.business_id\n   FROM profiles\n  WHERE ((profiles.id = auth.uid()) AND (profiles.role = 'owner'::text))))",
    "with_check": "(id = ( SELECT profiles.business_id\n   FROM profiles\n  WHERE ((profiles.id = auth.uid()) AND (profiles.role = 'owner'::text))))"
  }
]


table definion:
create table public.businesses (
  id uuid not null default gen_random_uuid (),
  name text not null,
  address text not null,
  phone text not null,
  currency text null,
  created_at timestamp with time zone null default now(),
  updated_at timestamp with time zone null default now(),
  owner_id uuid null,
  constraint businesses_pkey primary key (id),
  constraint businesses_owner_id_fkey foreign KEY (owner_id) references auth.users (id)
) TABLESPACE pg_default;
Was this page helpful?