https://supabase.com/ logo
#sql
Title
# sql
d

dailylurker

08/12/2021, 12:25 PM
when we insert a new record and RLS is enabled does it trigger policies other than update? I am getting RLS violation when I try to create a new row and my only policy right now besides update is read
b

burggraf

08/12/2021, 2:29 PM
I ran into an issue when I tried to create RLS where I wanted to allow a user to
insert
data but not be able to read (
select
) -- sort of a logging system.
Realized that when I was doing inserts then the API was trying to read info on the insert to send it back to the client (id, etc) so it would fail.
Copy code
public saveGameData = async (gamedata: GameData) => {
    const { data, error } = await supabase
    .from('game_data')
    .insert(gamedata,{returning: 'minimal'});
    return { data, error };
  }
Solution was that little gem:
returning: 'minimal'
which basically says "Just insert the data, I don't need you to read back info from the insert process."
d

dailylurker

08/13/2021, 7:14 AM
this is lit it does select after it
I wonder though do we have a way of knowing that the read is coming from an insert? or maybe a way to bypass the read policy if read is a result of insert
b

burggraf

08/13/2021, 12:39 PM
The
returning: 'minimal'
part bypasses the read after the insert, but you can't bypass the read policy AFAIK.