Skip to content

Commit 501b1aa

Browse files
authored
fix: bump gotrue-js/next version (#485)
* fix: bump gotrue-js/next version * bump gotrue/next version * fix: remove multitab stuff * remove redundant tests
1 parent 0ec5c69 commit 501b1aa

File tree

4 files changed

+9
-67
lines changed

4 files changed

+9
-67
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"dependencies": {
4040
"@supabase/functions-js": "^1.3.3",
41-
"@supabase/gotrue-js": "^1.23.0-next.6",
41+
"@supabase/gotrue-js": "^1.23.0-next.8",
4242
"@supabase/postgrest-js": "^1.0.0-next.2",
4343
"@supabase/realtime-js": "^1.7.3",
4444
"@supabase/storage-js": "^1.8.0-next.1",

src/SupabaseClient.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { RealtimeChannel, RealtimeClient, RealtimeClientOptions } from '@supabas
99
import { SupabaseStorageClient } from '@supabase/storage-js'
1010
import { DEFAULT_HEADERS } from './lib/constants'
1111
import { fetchWithAuth } from './lib/fetch'
12-
import { isBrowser, stripTrailingSlash } from './lib/helpers'
12+
import { stripTrailingSlash } from './lib/helpers'
1313
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
1414
import { SupabaseRealtimeClient } from './lib/SupabaseRealtimeClient'
1515
import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions } from './lib/types'
@@ -48,7 +48,6 @@ export default class SupabaseClient<
4848
protected functionsUrl: string
4949
protected realtime: RealtimeClient
5050
protected rest: PostgrestClient<Database, SchemaName>
51-
protected multiTab: boolean
5251
protected storageKey: string
5352
protected fetch?: Fetch
5453
protected changedAccessToken: string | undefined
@@ -68,7 +67,6 @@ export default class SupabaseClient<
6867
* @param options.detectSessionInUrl Set to "true" if you want to automatically detects OAuth grants in the URL and signs in the user.
6968
* @param options.headers Any additional headers to send with each network request.
7069
* @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.
7270
* @param options.fetch A custom fetch implementation.
7371
*/
7472
constructor(
@@ -98,7 +96,6 @@ export default class SupabaseClient<
9896

9997
const settings = { ...DEFAULT_OPTIONS, ...options, storageKey: this.storageKey }
10098

101-
this.multiTab = settings.auth?.multiTab ?? false
10299
this.headers = { ...DEFAULT_HEADERS, ...options?.headers }
103100
this.shouldThrowOnError = settings.shouldThrowOnError || false
104101

@@ -114,7 +111,6 @@ export default class SupabaseClient<
114111
})
115112

116113
this._listenForAuthEvents()
117-
this._listenForMultiTabEvents()
118114

119115
// In the future we might allow the user to pass in a logger to receive these events.
120116
// this.realtime.onOpen(() => console.log('OPEN'))
@@ -271,7 +267,6 @@ export default class SupabaseClient<
271267
detectSessionInUrl,
272268
localStorage,
273269
cookieOptions,
274-
multiTab,
275270
storageKey,
276271
}: SupabaseAuthClientOptions,
277272
headers?: Record<string, string>,
@@ -291,7 +286,6 @@ export default class SupabaseClient<
291286
localStorage,
292287
fetch,
293288
cookieOptions,
294-
multiTab,
295289
})
296290
}
297291

@@ -302,33 +296,6 @@ export default class SupabaseClient<
302296
})
303297
}
304298

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-
332299
private _listenForAuthEvents() {
333300
let data = this.auth.onAuthStateChange((event, session) => {
334301
this._handleTokenChanged(event, session?.access_token, 'CLIENT')
@@ -347,9 +314,6 @@ export default class SupabaseClient<
347314
) {
348315
// Token has changed
349316
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!)
353317

354318
this.changedAccessToken = token
355319
} else if (event === 'SIGNED_OUT' || event === 'USER_DELETED') {

test/client.test.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ test('it should throw an error if no valid params are provided', async () => {
1515
expect(() => createClient(URL, '')).toThrowError('supabaseKey is required.')
1616
})
1717

18-
test('it should not cache Authorization header', async () => {
19-
supabase.auth.setAuth('token1')
20-
supabase.rpc('')
21-
expect(supabase.auth.session()?.access_token).toBe('token1')
22-
23-
supabase.auth.setAuth('token2')
24-
supabase.rpc('')
25-
expect(supabase.auth.session()?.access_token).toBe('token2')
26-
})
27-
2818
describe('Custom Headers', () => {
2919
test('should have custom header set', () => {
3020
const customHeader = { 'X-Test-Header': 'value' }
@@ -36,18 +26,6 @@ describe('Custom Headers', () => {
3626

3727
expect(getHeaders).toHaveProperty('X-Test-Header', 'value')
3828
})
39-
40-
test('should allow custom Authorization header', () => {
41-
const customHeader = { Authorization: 'Bearer custom_token' }
42-
supabase.auth.setAuth('override_me')
43-
44-
const request = createClient(URL, KEY, { headers: customHeader }).rpc('')
45-
46-
// @ts-ignore
47-
const getHeaders = request.headers
48-
49-
expect(getHeaders).toHaveProperty('Authorization', 'Bearer custom_token')
50-
})
5129
})
5230

5331
// Socket should close when there are no open connections

0 commit comments

Comments
 (0)