I am trying to upload a file to a supabase bucket that contains RLS policies for insertion
BEGIN;ALTER POLICY "Allow users to insert avatar photo" ON "storage"."objects" WITH CHECK (((bucket_id = 'avatar'::text) AND ((( SELECT auth.uid() AS uid))::text = owner_id)));COMMIT;
I am using ssr authtentication like it is explained on the documentation (https://supabase.com/docs/guides/auth/server-side/creating-a-client?queryGroups=framework&framework=nextjs&queryGroups=environment&environment=client-component)so for the client side supabase client I have this code
const supabase = () => createBrowserClient(process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!);
and then for uploading the file to the bucket I have this code
const {error:avatarError} = await supabase.storage.from("avatar").upload(avatar_path,image,{upsert:true});
When I try to do this operation I get the following error log on the supabase side
{"event_message": "new row violates row-level security policy (USING expression) for table "objects"","id": "8db38f28-ffa1-4106-9a53-08390db10f2b","metadata": \[{"file": null,"host": "db-rvjswuemqjmlhfyyopkp","metadata": \[\],"parsed": \[{"application_name": "Supavisor","backend_type": "client backend","command_tag": "INSERT","connection_from": "2a05:d018:135e:1602:712:a4de:94b6:40e6:54822","context": null,"database_name": "postgres","detail": null,"error_severity": "ERROR","hint": null,"internal_query": null,"internal_query_pos": null,"leader_pid": null,"location": null,"process_id": 527687,"query": "insert into "objects" ("bucket_id", "metadata", "name", "owner", "owner_id", "version") values ($1, DEFAULT, $2, $3, $4, $5) on conflict ("name", "bucket_id") do update set "version" = $6,"owner" = $7,"owner_id" = $8 returning \*","query_id": -1540017731558507800,"query_pos": null,"session_id": "666d6cf3.80d47","session_line_num": 4,"session_start_time": "2024-06-15 10:29:07 UTC","sql_state_code": "42501","timestamp": "2024-06-15 10:31:02.911 UTC","transaction_id": 23022,"user_name": "supabase_storage_admin","virtual_transaction_id": "6/484678"}\],"parsed_from": null,"project": null,"source_type": null}\],"timestamp": 1718447462911000}
my authentication works fine if its an action on the server side but with this browser client I am unable to authenticate myself to supabase.