Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using different schema for Supabase prevents build, results in error #478

Open
2 tasks done
damywise opened this issue Sep 20, 2023 · 2 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@damywise
Copy link

damywise commented Sep 20, 2023

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Heya, I'm having trouble trying to use different table schema using Supabase for the template refine project

// utility/supabaseClient.ts
export const supabaseClient = createClient(SUPABASE_URL, SUPABASE_KEY, {
    db: {
// problematic part vv
        schema: "custom",
    },
    auth: {
        persistSession: true,
    },
});

That exact code results in the following error.

22:08:57.278    Executing user command: npm run build
22:08:57.892    
22:08:57.892    > data-provider-supabase@3.25.0 build
22:08:57.892    > tsc && refine build
22:08:57.892    
22:09:02.920    src/App.tsx(328,48): error TS2345: Argument of type 'SupabaseClient<any, "custom", any>' is not assignable to parameter of type 'SupabaseClient<any, "public", any>'.
22:09:02.921      Type '"custom"' is not assignable to type '"public"'.
22:09:02.921    src/App.tsx(329,48): error TS2345: Argument of type 'SupabaseClient<any, "custom", any>' is not assignable to parameter of type 'SupabaseClient<any, "public", any>'.
22:09:02.967    Failed: build command exited with code: 2
22:09:03.827    Failed: error occurred while running build command

To Reproduce

  1. Get the Supabase refine template
  2. Change supabaseClient options schema from "public" to anything else
  3. npm run build
  4. Error

Expected behavior

Works

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: macOS
  • Browser (if applies): any
  • Version of supabase-js: ^2.7.0
  • Version of Node.js: v18.17.1

Additional context

Type '"product"' is not assignable to type '"public"'.ts(2322)
---
(property) schema?: ("public" extends keyof Database ? "public" : string & keyof Database) | undefined

Also npm start works but npm run build doesn't

@damywise damywise added the bug Something isn't working label Sep 20, 2023
@steve-chavez steve-chavez transferred this issue from supabase/supabase-js Sep 20, 2023
@garygcchiu
Copy link

Running into the same problem. It's a blocker for running Edge Function tests as well if I need to create a client and use data in a non-public schema.

error: TS2322 [ERROR]: Type 'SupabaseClient<any, string, any>' is not assignable to type 'SupabaseClient<any, "public", any>'.
  Type 'string' is not assignable to type '"public"'.
    var client: SupabaseClient = createClient(supabaseUrl, supabaseKey, options) // options has db: { schema: 'my-schema' }
        ~~~~~~

@gerynugrh
Copy link

A way to solve this would be to write it like this:

  const supabase = createClient<Omit<Database, "public">>(
    config.SUPABASE_URL,
    config.SUPABASE_SERVICE_ROLE_KEY,
    {
      db: {
        schema: "custom",
      },
    }
  );

It seems that the typing only allow public if public is a key of Database. Otherwise, it would allow the schema to be all possible keys of Database. Hence, the removal of the key public above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants