SupabaseS
Supabase2mo ago
DAAG

Storage RLS Help

Hi folks,
Uploading file to storage is failing even tho the rls should pass, i wrote queries to test and they call pass.

Here are the policies:
for INSERT:
((bucket_id = 'clinic'::text) AND (EXISTS ( SELECT 1
   FROM ("user" u
     JOIN clinic c ON ((c.organization_id = u.organization_id)))
  WHERE ((u.id = ( SELECT auth.uid() AS uid)) AND ((c.id)::text = (storage.foldername(c.name))[1])))))


call from my next app:
// path value is: 2f5fc207-a7fe-4f89-a490-f38ffcac7abf/images/12NacYB
export async function uploadClinicFile({ supabaseClient, file, path }: UploadClinicFileArgs) {
    // return await test({ supabaseClient, path, file });
    const { data, error } = await supabaseClient.storage.from("clinic").upload(path, file);
    if (error) {
        console.error({ error, function: "uploadClinicFile" });
        return null;
    }
    return data;
}


await supabaseClient.auth.getUser()
returns user with role authenticated and id
007866e0-73d1-4e56-9d7f-f425ba10da06

user.organization_id is
86b741b2-a996-47be-9cf6-117b99653dc1

there exists a row in public.clinic with organization_id equal to
86b741b2-a996-47be-9cf6-117b99653dc1
and id equal to
2f5fc207-a7fe-4f89-a490-f38ffcac7abf
which is what i passed in from the next app call.

WHAT AM I DOIND WRONG?
Was this page helpful?