Skip to content

Supabase adapter with supabase storage error possible workaround #7452

Open
@Zhumatic

Description

@Zhumatic

What is the improvement or update you wish to see?

  1. Create client accroding to the supabase adapter docs like this:
const { supabaseAccessToken } = session;

const supabase = createClient(
  process.env.NEXT_PUBLIC_SUPABASE_URL,
  process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
  {
    global: {
      headers: {
        Authorization: `Bearer ${supabaseAccessToken}`,
      },
    },
  }
);
  1. Then using this client to perform supabase storage upload will result in error: parent resource cannot be found. Supabase postgres log shows this error actually is:
insert or update on table "objects" violates foreign key constraint "objects_owner_fkey

If you look at the storage objects table definition will find following

constraint objects_owner_fkey foreign key (owner) references auth.users (id)
  1. Possible cause of the problem: next_auth schema is created and used in order to implement next auth instead of the default auth schema.

  2. Possible workaround:

alter table storage.objects
drop constraint objects_owner_fkey,
add constraint objects_owner_fkey
   foreign key (owner)
   references next_auth.users(id)

after this sql action, above supabase client works with storage upload, and next_auth.user(id) is loaded into the "owner" column of the objects table upon upload action.

  1. Is it a good idea to mention the inconsistency and possible official solution in the supabase adapter documentation?

Is there any context that might help us understand?

related issue from supabase:
"Storage.objects table should not use fk constraint with owners column on auth.users id column "
supabase/storage#276

Does the docs page already exist? Please link to it.

https://authjs.dev/reference/adapter/supabase

Metadata

Metadata

Assignees

No one assigned

    Labels

    adaptersChanges related to the core code concerning database adaptersdocsRelates to documentationhelp-neededThe maintainer needs help due to time constraint/missing knowledgesupabase@auth/supabase-adaptertriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions