@@ -9,7 +9,7 @@ import { RealtimeChannel, RealtimeClient, RealtimeClientOptions } from '@supabas
9
9
import { SupabaseStorageClient } from '@supabase/storage-js'
10
10
import { DEFAULT_HEADERS } from './lib/constants'
11
11
import { fetchWithAuth } from './lib/fetch'
12
- import { isBrowser , stripTrailingSlash } from './lib/helpers'
12
+ import { stripTrailingSlash } from './lib/helpers'
13
13
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
14
14
import { SupabaseRealtimeClient } from './lib/SupabaseRealtimeClient'
15
15
import { Fetch , GenericSchema , SupabaseClientOptions , SupabaseAuthClientOptions } from './lib/types'
@@ -48,7 +48,6 @@ export default class SupabaseClient<
48
48
protected functionsUrl : string
49
49
protected realtime : RealtimeClient
50
50
protected rest : PostgrestClient < Database , SchemaName >
51
- protected multiTab : boolean
52
51
protected storageKey : string
53
52
protected fetch ?: Fetch
54
53
protected changedAccessToken : string | undefined
@@ -68,7 +67,6 @@ export default class SupabaseClient<
68
67
* @param options.detectSessionInUrl Set to "true" if you want to automatically detects OAuth grants in the URL and signs in the user.
69
68
* @param options.headers Any additional headers to send with each network request.
70
69
* @param options.realtime Options passed along to realtime-js constructor.
71
- * @param options.multiTab Set to "false" if you want to disable multi-tab/window events.
72
70
* @param options.fetch A custom fetch implementation.
73
71
*/
74
72
constructor (
@@ -98,7 +96,6 @@ export default class SupabaseClient<
98
96
99
97
const settings = { ...DEFAULT_OPTIONS , ...options , storageKey : this . storageKey }
100
98
101
- this . multiTab = settings . auth ?. multiTab ?? false
102
99
this . headers = { ...DEFAULT_HEADERS , ...options ?. headers }
103
100
this . shouldThrowOnError = settings . shouldThrowOnError || false
104
101
@@ -114,7 +111,6 @@ export default class SupabaseClient<
114
111
} )
115
112
116
113
this . _listenForAuthEvents ( )
117
- this . _listenForMultiTabEvents ( )
118
114
119
115
// In the future we might allow the user to pass in a logger to receive these events.
120
116
// this.realtime.onOpen(() => console.log('OPEN'))
@@ -271,7 +267,6 @@ export default class SupabaseClient<
271
267
detectSessionInUrl,
272
268
localStorage,
273
269
cookieOptions,
274
- multiTab,
275
270
storageKey,
276
271
} : SupabaseAuthClientOptions ,
277
272
headers ?: Record < string , string > ,
@@ -291,7 +286,6 @@ export default class SupabaseClient<
291
286
localStorage,
292
287
fetch,
293
288
cookieOptions,
294
- multiTab,
295
289
} )
296
290
}
297
291
@@ -302,33 +296,6 @@ export default class SupabaseClient<
302
296
} )
303
297
}
304
298
305
- private _listenForMultiTabEvents ( ) {
306
- if ( ! this . multiTab || ! isBrowser ( ) || ! window ?. addEventListener ) {
307
- return null
308
- }
309
-
310
- try {
311
- return window ?. addEventListener ( 'storage' , ( e : StorageEvent ) => {
312
- if ( e . key === this . storageKey ) {
313
- const newSession = JSON . parse ( String ( e . newValue ) )
314
- const accessToken : string | undefined =
315
- newSession ?. currentSession ?. access_token ?? undefined
316
- const previousAccessToken = this . auth . session ( ) ?. access_token
317
- if ( ! accessToken ) {
318
- this . _handleTokenChanged ( 'SIGNED_OUT' , accessToken , 'STORAGE' )
319
- } else if ( ! previousAccessToken && accessToken ) {
320
- this . _handleTokenChanged ( 'SIGNED_IN' , accessToken , 'STORAGE' )
321
- } else if ( previousAccessToken !== accessToken ) {
322
- this . _handleTokenChanged ( 'TOKEN_REFRESHED' , accessToken , 'STORAGE' )
323
- }
324
- }
325
- } )
326
- } catch ( error ) {
327
- console . error ( '_listenForMultiTabEvents' , error )
328
- return null
329
- }
330
- }
331
-
332
299
private _listenForAuthEvents ( ) {
333
300
let data = this . auth . onAuthStateChange ( ( event , session ) => {
334
301
this . _handleTokenChanged ( event , session ?. access_token , 'CLIENT' )
@@ -347,9 +314,6 @@ export default class SupabaseClient<
347
314
) {
348
315
// Token has changed
349
316
this . realtime . setAuth ( token ! )
350
- // Ideally we should call this.auth.recoverSession() - need to make public
351
- // to trigger a "SIGNED_IN" event on this client.
352
- if ( source == 'STORAGE' ) this . auth . setAuth ( token ! )
353
317
354
318
this . changedAccessToken = token
355
319
} else if ( event === 'SIGNED_OUT' || event === 'USER_DELETED' ) {
0 commit comments