Skip to content

fix: Only warn if multiple clients share the same storage-key #1100

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
wants to merge 2 commits into
base: master
Choose a base branch
from

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/@[email protected]/node_modules/@supabase/supabase-js/src/lib/SupabaseAuthClient.ts:6:5)
+    at SupabaseClient._initSupabaseAuthClient (/home/user/dev/node_modules/.pnpm/@[email protected]/node_modules/@supabase/supabase-js/src/SupabaseClient.ts:304:12)
+    at new SupabaseClient (/home/user/dev/node_modules/.pnpm/@[email protected]/node_modules/@supabase/supabase-js/src/SupabaseClient.ts:107:24)
+    at createClient (/home/user/dev/node_modules/.pnpm/@[email protected]/node_modules/@supabase/supabase-js/src/index.ts:40:10)
+    at createBrowserClient (/home/user/dev/node_modules/.pnpm/@[email protected]_@[email protected]/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/@[email protected]/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}});

@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 5 times, most recently from 57eac5a to e6d7326 Compare August 13, 2025 22:38
sh41 added 2 commits August 13, 2025 23:38
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.
The same prefix has been added to the warning for consistency
 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.
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.
The same prefix has been added to the warning for consistency
 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.
@sh41 sh41 force-pushed the multiple-clients-warning-by-storage-key branch from e6d7326 to a9d6505 Compare August 13, 2025 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant