Open
Description
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.

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"})