1

So I am using "@supabase/supabase-js": "2.4.1" and I cant seem to change dynamically the schema.

Previously using v1 I can just pass the schema to the custom hooks and called the supabse client like so

const newOptions = {
  ...options,
  schema: schema || 'public',
};

And use the options directly like so

const supabase = createClient(
  // @ts-ignore
  process.env['NX_SUPABASE_URL'],
  process.env['NX_SUPABASE_ANON_KEY'],
  newOptions
);
const firstIndex = page * size - size;
const secondIndex = page * size - 1;
const { data, error: dataError } = await supabase
  .from(table)
  .select(select)
  .range(firstIndex, secondIndex);

But now using v2, the supabse client is declared on the root of the app and I tried to set the options like this but not working

 const [supabaseOptions, setSupabaseOptions] = useState({});
 const [supabaseClient] = useState(() => createBrowserSupabaseClient(supabaseOptions));

  return (
    <SessionContextProvider
      supabaseClient={supabaseClient}
      initialSession={pageProps.initialSession}
    >
      <Layout>
        <Component {...pageProps} setSupabaseOptions={setSupabaseOptions} />
      </Layout>
    </SessionContextProvider>
  );

Setting the options based on the component/page

  useEffect(() => {
    console.log('props', props);
    props.setSupabaseOptions(s => ({
      ...s,
      options: {
        ...s.options,
        schema: 'custom',
      },
    }));
  }, []);
Eko Andri
  • 181
  • 2
  • 5
  • 17
  • Currently you'd ave to initiate a separate client per schema, which is not ideal because of Auth etc. We're working on a way to set the schema dynamically. Would appreciate your input here: https://github.com/supabase/postgrest-js/issues/280 – thorwebdev Jan 30 '23 at 06:14

0 Answers0