Hacker News new | past | comments | ask | show | jobs | submit | solo-fox's comments login

*Description:*

I'm experiencing an issue where a `SELECT` query on the `projects` table returns an empty array, even though there is data present in the table. This issue occurs when Row-Level Security (RLS) is enabled. Disabling RLS allows the query to return the expected data.

*Circumstances*:

This occurs under the following conditions:

- The user_id column is unique and directly linked to auth.users. - Row-Level Security (RLS) is enabled on the projects table. - An RLS policy is in place to allow all / one users/ user to select their own data / data. - Executing the query in the SQL editor also returns an empty result.

*Steps to Reproduce:*

1. Enable RLS on the `projects` table: ```sql ALTER TABLE projects ENABLE ROW LEVEL SECURITY; ``` 2. Define the following RLS policy to allow users to read their own projects: ```sql CREATE POLICY "Users can read their own projects" ON projects FOR SELECT USING (auth.uid() = user_id); ``` 3. Execute the following query using the Supabase client: ```javascript const { data, error } = await supabase .from('projects') .select('') .eq('user_id', '<USER_ID>'); ```

*Expected Behavior:*

The query should return the projects associated with the specified `user_id`.

*Actual Behavior:*

The query returns an empty array (`[]`), despite the `projects` table containing relevant data.

*Additional Information:*

- *Authentication:* The user is authenticated, and `auth.uid()` returns the correct user ID. - *RLS Policies:* The only active policy on the `projects` table is the one mentioned above. - *Testing:* Disabling RLS on the `projects` table allows the query to return the expected data.

I've also referred to the Supabase troubleshooting guide on this topic but haven't found a resolution:

[Why is my select returning an empty data array and I have data in the table?](https://supabase.com/docs/guides/troubleshooting/why-is-my-s...)

Additionally, I came across a similar discussion, but the solutions provided did not resolve my issue:

[SOLVED Empty Array · supabase · Discussion #3780](https://github.com/orgs/supabase/discussions/3780)

*Request for Assistance:*

I'm seeking guidance on why the query returns an empty array when RLS is enabled, despite having the appropriate policy in place and existing data that matches the query criteria. Any insights or suggestions would be greatly appreciated.

---

Please ensure to replace `<USER_ID>` with the actual user ID you're testing with. Providing specific details and referencing related discussions can help the Supabase team understand and address your issue more effectively.


Corrected URLs:

- web : https://reviewnow.vercel.app/auth/sigin -> You can use dummy email and password - github : https://github.com/solo-fox/reviewnow

If you find the idea great and want to contribute as a co-developer, file a PR.

Happy coding.


Thanks,

and you can visit https://reviewnow.vercel.app/auth/sigin to create an account. As said we are in a very early stage so feel free to write issues and feedback. You can use dummy data no confirmation will be sended at all. If you planing to be a co-dev file a pr and you will become a testing email so you can test the app with us!

Happy day.


Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: