6

I have a messages table , under a 'public' schema in Supabase. I'm trying to fetch all rows from my local dev environment, but nothing is returned.

I'm trying:

const response = await supabase.from('messages').select('*');

I see the request in the Supabase logs:seems to be responded with 200OK

Using Sveltekit as a client, and the load function:

/** @type {import('./$types').PageLoad} */
export async function load() {
    const response = await supabase.from('messages').select('*');

    return { response };
}

Here's the log of the response:

{@debug} /src/routes/+page.svelte (6:1)
{
  data: {
    response: {
      error: null,
      data: [],
      count: null,
      status: 200,
      statusText: 'OK'
    }
  }
}

and here's the table: enter image description here

3 Answers 3

11

OP has already solved the problem by disabling RLS. I am going to provide further context on how this solved the problem.

RLS stands for Row Level Security, it makes it so that only the owner of the row can view their own data. Let's say user A inserts a line of data, only user A can see it. If you run select * as user B, you won't be able to see it.

This helps prevent other users from interacting with a user's items.

In your case, there are two other ways of dealing with this:

1. if you are querying as the admin

If you are the admin and should have access to all data, to initialize the supabase javascript client, you can use the service key instead of the anon key, which will give you all permissions

2. if you just want everyone to view everything

Inside the rules for row-level security, you can just disable the rule for SELECT, but don't disable RLS for insert, update and delete. Then users can only insert, update and delete their own things, but can view everyone's things.

1
  • 1
    Very useful complementary information, thank you. Jan 7, 2023 at 15:15
3

I had enabled "RLS" https://supabase.com/docs/learn/auth-deep-dive/auth-row-level-security thats why there was no results.

Disabling it did the trick. More info on RLS: https://supabase.com/docs/guides/auth/row-level-security

2
2

This is probably a niche sub-problem, but even after disabling RLS I still wasn't able to get anything returned. I had named my table "store" to keep track of Shopify stores. That name must be reserved because changing the name immediately fixed it. That detail is probably right there in the docs, but learning as I go, I didn't see that. Now that it's working I'm impressed how easy it is!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.