User authentication with RLS receive an empty response when requested via Postman #36071
-
|
I create a supabase database with user authentication. When Auth user is created the same user is automatically created in my internal table users, where the auth_user_id is also added in a column for reference (link). Everything works as intended. By default I set RLS plocies disabled for users table and to test this I use Postman by doing the following actions:
or
The response received in Postman depends on the status of the only RLS policy I have defined in sudabase for table users. Below the RLS policy being used: or even When RLS policy is disabled When RLS policy is enabled I already tried to adjust the RLS Policy in different ways but always receive an empty response when requesting it via Postman. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
What is your id column in public users? You show auth_user_id in one policy and user_id in the 2nd policy. The 2nd policy looks correct IF you have a column called user_id. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, Thanks for your feedback, it provides enough info. I see it was a rookie mistake variable names were not correctly written. I just updated the policy as follows (via SQL Editor) and now it is working. DROP POLICY IF EXISTS "Allow users to read their own data" ON public.users; CREATE POLICY "Allow users to read their own data" Thanks a lot man! |
Beta Was this translation helpful? Give feedback.
What is your id column in public users? You show auth_user_id in one policy and user_id in the 2nd policy. The 2nd policy looks correct IF you have a column called user_id.
Does that column have the user id from the sub claim of the JWT in it?
Check the JWT you get back from sign in with jwt.io to see if it is the user you expect.