5

It seems I am always returning an empty array when trying to pull data from my tables. This is how I am doing it, after following the docs and several tutorials.

const [tableData, setTableData] = useState([]);

  async function getTableData() {
    let { data, error } = await supabase
      .from('SignalJourneyAudienceConstraints')
      .select('*');

    setTableData(data);
    console.log(tableData);
  }

  useEffect(() => {
    getTableData();
  }, []);

I have data in the table as so.

enter image description here

The only thing I can think of is the naming of the table??

I have also tried the following

let { data: SignalJourneyAudienceConstraints, error } = await supabase
  .from('SignalJourneyAudienceConstraints')
  .select('*')

But getting an error ReferenceError: data is not defined and in VSC I'm getting All destructured elements are unused.ts(6198) with the above.

I have always seen tutorials just use data though.

mrpbennett
  • 1,527
  • 15
  • 40

4 Answers4

17

I had to turn off RLS on my tables.

mrpbennett
  • 1,527
  • 15
  • 40
2

you should disable RLS (not secure) or define policy for your table . (every table in your project has its own policies and should create ruls seprately)

Mojito
  • 51
  • 3
2

I was getting back no records even with RLS turned off. Turns out NextJS was caching the response.

Hard-refreshing (using cmd-shift-r or holding down the refresh button in Chrome) worked for me.

Kaiden
  • 188
  • 3
  • 8
1

Open your supabase project dashboard. Then go to the "Authentication" menu on the side left. Then open "Configuration" -> "Policies".

enter image description here

Then create "New Policy" for your table.

And put true inside the "USING expression" column.

Please see my screenshot below; enter image description here

It will give you an authorization to access the Public table that using RLS. RLS is important to used, because on production it make your table cannot edit by anyone. And you can set the "Allowed Operation" (see the second screenshot) only for SELECT.

So, It doesn't matter if the anon key is scattered. That was only can see the content but cannot change it up.