how to create storage RLS policies

I am trying to create a storage bucket - where I am allowing users to upload profile pictures. This is the RLS policy I am trying to implement, but its not working. Attached is my RLS policy and the storage bucket layout.

Here is the upload function (javascript) as well as the output

filePathexample: public/{User UID}/{random UID}.jpeg

const { data: uploadData, error: uploadError } = await supabase.storage
        .from("avatars") 
        .upload(filePath, avatar, {
          cacheControl: "3600",
          upsert: true
        });


My goal is to only let users upload/edit/delete their own profile images. Any suggestions on what I am doing wrong? The error I keep getting is
Upload error: {
  statusCode: '403',
  error: 'Unauthorized',
  message: 'new row violates row-level security policy'
}
Screenshot_2025-01-26_at_10.43.14_PM.png
Screenshot_2025-01-26_at_10.44.38_PM.png
Was this page helpful?