Skip to content

createClient pattern lacks of extensibility with multi-schema usage (singleton gotrue warning) #1394

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

Open
softmarshmallow opened this issue Apr 21, 2025 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@softmarshmallow
Copy link

softmarshmallow commented Apr 21, 2025

I am constantly getting warning from supabase.

Multiple GoTrueClient instances detected in the same browser context. It is not an error, but this should be avoided as it may produce undefined behavior when used concurrently under the same storage key. 
Image

I am using multiple clients with singleton: false since I am using multiple schema, and client instanciation with singleton does not allow it.

e.g.

import type { Database } from "@/database.types";
import { createBrowserClient as _createBrowserClient } from "@supabase/ssr";

const __create_browser_client = <
  SchemaName extends string & keyof Database = "public" extends keyof Database
    ? "public"
    : string & keyof Database,
>(
  schema: SchemaName
) =>
  _createBrowserClient<Database, SchemaName>(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
    {
      db: {
        schema: schema,
      },
      isSingleton: false,
    }
  );

export const createBrowserClient = () =>
  __create_browser_client<"public">("public");

export const createBrowserFormsClient = () =>
  __create_browser_client<"grida_forms">("grida_forms");

export const createBrowserCommerceClient = () =>
  __create_browser_client<"grida_commerce">("grida_commerce");

export const createBrowserCanvasClient = () =>
  __create_browser_client<"grida_canvas">("grida_canvas");

export const createBrowserWWWClient = () =>
  __create_browser_client<"grida_www">("grida_www");

export const createBrowserWestReferralClient = () =>
  __create_browser_client<"grida_west_referral">("grida_west_referral");

(this is not a @supabase/ssr problem, but a supabase-js problem)

What is the best practice when using multiple schema? do you have plans for supporting switching schema on-the-go with a singleton instance?

e.g.

// switch schema with builder pattern
const client = createClient()
client.schema("other_schema").from("...")


// or.. (multi singleton by group)

const client = createClient({singleton: true, singletone_group: "public"})
const otherClient = createClient({singleton: true, singletone_group: "other_schema"})


// core client - consumer client pattern
const base = createCoreClient()
const client = createClient(base)
const otherClient = createClient<"other_schema">(base,  {schema: "other_schema"})
@softmarshmallow softmarshmallow added the documentation Improvements or additions to documentation label Apr 21, 2025
@softmarshmallow softmarshmallow changed the title Best practice for non-singleton browser client for multi-schema createClient pattern lacks of extensibility with multi-schema usage (singleton gotrue warning) Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant