Hi, I'm having an issue where users with custom JWT roles (administrator and moderator) cannot upload files to storage and get:
upload failed — database error, code: 42P01
Regular authenticated users upload fine. Setup: I have a custom access token hook that replaces the role claim in the JWT with a custom role from my server.staff_members table:
if found then
v_new_claims := jsonb_set(v_new_claims, '{role}', to_jsonb(v_staff_role::text));
end if;
So for staff users, role in JWT becomes administrator or moderator instead of authenticated.
Custom roles:
do $$
begin
if not exists (select 1 from pg_roles where rolname = 'administrator') then
create role administrator noinherit nologin;
end if;
if not exists (select 1 from pg_roles where rolname = 'moderator') then
create role moderator noinherit nologin;
end if;
end
$$;
grant administrator to authenticator;
grant moderator to authenticator;
grant usage on schema management to administrator, moderator;
Storage policy (with check): Editing policy from storage.objects Docs Policy name A descriptive name for your policy
The user reports an issue where users with custom JWT roles (administrator and moderator) cannot upload files to storage, receiving a database error code 42P01. Regular authenticated users can upload without issues. The user has set up custom roles and granted schema access, but encounters the error only with employee roles.
Have you looked in the storage or Postgres log for error detail?
Give users access to own folder 1oj01fe_0 41/63 Target roles Apply policy to the selected roles
administrator authenticated moderator WITH CHECK expression
Provide a SQL conditional expression that returns a boolean.
1
((bucket_id = 'avatars'::text) AND (( SELECT (auth.uid())::text AS uid) = (storage.foldername(name))[1]))
Issue: Error code 42P01 indicates that the relationship does not exist—however, this applies only to employee roles. When a regular, authenticated user uploads a file, everything works correctly. When a user with an employee role uploads a file, the operation fails and error 42P01 appears.
Question: Is there a known issue regarding custom JWT roles and data uploads to the database in Supabase? Could additional schema access granted to custom roles cause error 42P01 during database operations?