Supabase Storage (RLS) Policies Not Working As Expected

PROBLEM I am new to using Supabase, so my apologies ahead of time if I am missing something obvious.

I want to add RLS to my storage bucket ("files"). I have a database table titled "validUser" which contains information on some of my users; it has a column (uid) containing valid users' ids (of type uuid). I want to write a policy that allows an authenticated user to access my files bucket if they are registered in my validUser table. To do this, I have been trying policies similar to this one, but they don't seem to work.

When I enable such policies and then upload a file, I run into this error: {"statusCode":"400","error":"Error","message":"headers must have required property 'authorization'"}

RLS IMAGE

WHAT I'VE TRIED When I simplify my policy such that the later part is SELECT 1 (FROM "validUser"), it still doesn't work despite validUser being populated. However, when I run SELECT 1 (FROM "validUser") in Supabase's SQL editor, it returns true as expected.

I have tried using other populated datatables (e.g., "company"), but it does not fix anything.

Interestingly, when I generalize the policy such that it only contains the first part (bucket_id...), everything works as expected -- I can upload files from my app. However, I want a more restricted RLS.

Is there something obvious that I am doing wrong here? Or is there an easy way I can debug this? I am unsure on what my next steps should be to solve this.

Upvotes: 0

Views: 462

Answers (0)

Related Questions