Skip to content

Commit a9d6505

Browse files
committed
fix: Only warn if multiple clients share a storage-key
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.
1 parent 1b2ed11 commit a9d6505

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

test/GoTrueClient.browser.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ describe('GoTrueClient in browser environment', () => {
110110
try {
111111
consoleWarnSpy = jest.spyOn(console, 'warn')
112112
consoleTraceSpy = jest.spyOn(console, 'trace')
113-
getClientWithSpecificStorageKey('test-storage-key')
114-
getClientWithSpecificStorageKey('test-storage-key')
113+
getClientWithSpecificStorageKey('same-storage-key')
114+
getClientWithSpecificStorageKey('same-storage-key')
115115
expect(consoleWarnSpy).toHaveBeenCalledTimes(1)
116116
expect(consoleWarnSpy).toHaveBeenCalledWith(
117117
expect.stringMatching(
118-
/GoTrueClient@test-storage-key:1 .* 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./
118+
/GoTrueClient@same-storage-key:1 .* 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./
119119
)
120120
)
121121
expect(consoleTraceSpy).not.toHaveBeenCalled()
@@ -131,17 +131,17 @@ describe('GoTrueClient in browser environment', () => {
131131
try {
132132
consoleWarnSpy = jest.spyOn(console, 'warn')
133133
consoleTraceSpy = jest.spyOn(console, 'trace')
134-
getClientWithSpecificStorageKey('test-storage-key')
135-
getClientWithSpecificStorageKey('test-storage-key', { debug: true })
134+
getClientWithSpecificStorageKey('identical-storage-key')
135+
getClientWithSpecificStorageKey('identical-storage-key', { debug: true })
136136
expect(consoleWarnSpy).toHaveBeenCalledTimes(1)
137137
expect(consoleWarnSpy).toHaveBeenCalledWith(
138138
expect.stringMatching(
139-
/GoTrueClient@test-storage-key:1 .* 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./
139+
/GoTrueClient@identical-storage-key:1 .* 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./
140140
)
141141
)
142142
expect(consoleTraceSpy).toHaveBeenCalledWith(
143143
expect.stringMatching(
144-
/GoTrueClient@test-storage-key:1 .* 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./
144+
/GoTrueClient@identical-storage-key:1 .* 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./
145145
)
146146
)
147147
} finally {
@@ -156,8 +156,8 @@ describe('GoTrueClient in browser environment', () => {
156156
try {
157157
consoleWarnSpy = jest.spyOn(console, 'warn')
158158
consoleTraceSpy = jest.spyOn(console, 'trace')
159-
getClientWithSpecificStorageKey('test-storage-key1')
160-
getClientWithSpecificStorageKey('test-storage-key2')
159+
getClientWithSpecificStorageKey('first-storage-key')
160+
getClientWithSpecificStorageKey('second-storage-key')
161161
expect(consoleWarnSpy).not.toHaveBeenCalled()
162162
expect(consoleTraceSpy).not.toHaveBeenCalled()
163163
} finally {
@@ -166,7 +166,7 @@ describe('GoTrueClient in browser environment', () => {
166166
}
167167
})
168168

169-
it('should not warn only when a second client with a duplicate key is created', () => {
169+
it('should warn only when a second client with a duplicate key is created', () => {
170170
let consoleWarnSpy
171171
let consoleTraceSpy
172172
try {

0 commit comments

Comments
 (0)