Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Conversation

sh41
Copy link

@sh41 sh41 commented Aug 13, 2025

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

A warning: 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. appears when using multiple clients, even if those clients do not share a storage-key.

What is the new behavior?

This allows use of multiple clients with different storage-keys, without the 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. warning appearing.

  • The storageKey has also been added to the prefix of the debug messages to help with tracing.
- GoTrueClient@0 (0.0.0) 2025-08-13T21:51:25.839Z #_acquireLock begin -1
+ GoTrueClient@sb-127-auth-token:0 (0.0.0) 2025-08-13T21:51:25.839Z #_acquireLock begin -1
  • The same prefix has been added to the warning for consistency.
- 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.
+ GoTrueClient@sb-127-auth-token:1 (0.0.0) 2025-08-13T21:51:26.455Z 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.
  • If debug messages are enabled, the warning will also output a trace in addition to the warning to assist the user in tracking down where their multiple instances are being created from.
- 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.
+ GoTrueClient@sb-127-auth-token:1 (0.0.0) 2025-08-13T21:51:26.455Z 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.
+ Trace: GoTrueClient@sb-127-auth-token:1 (0.0.0) 2025-08-13T21:51:26.455Z 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.
+    at new GoTrueClient (/home/steve/dev/auth-js/src/GoTrueClient.ts:256:17)
+    at new SupabaseAuthClient (/home/user/dev/node_modules/.pnpm/@supabase+supabase-js@2.55.0/node_modules/@supabase/supabase-js/src/lib/SupabaseAuthClient.ts:6:5)
+    at SupabaseClient._initSupabaseAuthClient (/home/user/dev/node_modules/.pnpm/@supabase+supabase-js@2.55.0/node_modules/@supabase/supabase-js/src/SupabaseClient.ts:304:12)
+    at new SupabaseClient (/home/user/dev/node_modules/.pnpm/@supabase+supabase-js@2.55.0/node_modules/@supabase/supabase-js/src/SupabaseClient.ts:107:24)
+    at createClient (/home/user/dev/node_modules/.pnpm/@supabase+supabase-js@2.55.0/node_modules/@supabase/supabase-js/src/index.ts:40:10)
+    at createBrowserClient (/home/user/dev/node_modules/.pnpm/@supabase+ssr@0.6.1_@supabase+supabase-js@2.55.0/node_modules/@supabase/ssr/src/createBrowserClient.ts:121:30)
+    at createBrowserClient (/home/user/dev/lib/supabase/client.ts:16:10)
+    at /home/user/dev/mycode/thatCreatesAClient.ts:16:29
+    at processTicksAndRejections (node:internal/process/task_queues:105:5)
+    at file:///home/user/dev/node_modules/.pnpm/@vitest+runner@3.2.4/node_modules/@vitest/runner/dist/chunk-hooks.js:752:20

Additional context

My specific use case for this is in tests where I want to have multiple clients running in parallel. One of them sets up fixtures and uses the service role, others represent different users. The nature of the tests is that they all run in the same instance, so the warning was appearing. Now I can instantiate the clients with unique storage keys and the warning will only appear if I actually have multiple clients that share those storage keys.

// example with supabase-js / ssr
import { createClient  } from "@supabase/supabase-js";
import { createBrowserClient  } from "@supabase/supabase-ssr";
const fixturesClient = createClient(supabaseUrl, serviceRoleKey, { auth: { storageKey: "FIXTURES_CLIENT"}});
// create fixtures
const userClient = createBrowserClient(supabaseUrl, anonKey, { auth: { storageKey: "USER"}});
// login user 
await userClient.auth.signInWithPassword({ email, password})

To enable debug messages with the Supabase client you can use the auth/debug flag:

createBrowserClient(supabaseUrl, anonKey, { auth: { debug: true}});

Potentially linked issues:
refinedev/refine#5094
refinedev/refine#5551
supabase/supabase-js#1394 (comment)
#725 (comment)

@sh41 sh41 force-pushed the multiple-clients-warning-by-storage-key branch from 026e716 to 1d1d581 Compare August 13, 2025 20:40
@sh41 sh41 closed this Aug 13, 2025
@sh41 sh41 reopened this Aug 13, 2025
@sh41 sh41 changed the title Only warn if multiple clients share the same storage-key fix: Only warn if multiple clients share the same storage-key Aug 13, 2025
@sh41 sh41 force-pushed the multiple-clients-warning-by-storage-key branch 6 times, most recently from e6d7326 to a9d6505 Compare August 13, 2025 22:38
@sh41 sh41 force-pushed the multiple-clients-warning-by-storage-key branch 2 times, most recently from f8fdc89 to 441bb03 Compare August 25, 2025 23:02
@sh41 sh41 force-pushed the multiple-clients-warning-by-storage-key branch from 441bb03 to a640451 Compare September 13, 2025 10:24
@sh41 sh41 force-pushed the multiple-clients-warning-by-storage-key branch 3 times, most recently from 01c5e9d to c9522a2 Compare September 25, 2025 08:50
Allow use of multiple clients with different storage-keys, without the `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.` warning appearing.

 - Add the storageKey to the prefix of the debug messages to help with tracing.
 - Add the same prefix the warning for consistency
 - If debug messages are enabled, also output a trace in addition to the warning to assist the user in tracking down where their multiple instances are being created from.

 Fixes: supabase#725
@sh41 sh41 force-pushed the multiple-clients-warning-by-storage-key branch from c9522a2 to a933578 Compare October 2, 2025 14:52
@mandarini
Copy link
Contributor

Hi @sh41 ! Thanks for the contribution and your patience.

This repository is deprecated and has moved to the new Supabase JS monorepo. I’m going to close it to keep the old repo tidy, before archiving.

If you believe this change is still needed, please open a new PR in the monorepo and include a link back to this thread for context:

Note: This repository is now archived, but you can still see your work, and if needed, copy it over to the new repo. No work is lost!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants