Skip to content

Commit 376689f

Browse files
authored
fix: Access localStorage lazily to avoid DOMExceptions in constrained envs when localStorage is provided using options (#252)
1 parent fd99728 commit 376689f

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

package-lock.json

Lines changed: 10 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
@@ -36,7 +36,7 @@
3636
"docs:json": "typedoc --json docs/spec.json --mode modules --includeDeclarations --excludeExternals"
3737
},
3838
"dependencies": {
39-
"@supabase/gotrue-js": "^1.17.0",
39+
"@supabase/gotrue-js": "^1.17.1",
4040
"@supabase/postgrest-js": "^0.33.3",
4141
"@supabase/realtime-js": "^1.1.3",
4242
"@supabase/storage-js": "^1.4.0"

src/SupabaseClient.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const DEFAULT_OPTIONS = {
1111
autoRefreshToken: true,
1212
persistSession: true,
1313
detectSessionInUrl: true,
14-
localStorage: globalThis.localStorage,
1514
headers: DEFAULT_HEADERS,
1615
}
1716

src/lib/SupabaseAuthClient.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import { GoTrueClient } from '@supabase/gotrue-js'
2+
import { SupabaseAuthClientOptions } from './types'
23

34
export class SupabaseAuthClient extends GoTrueClient {
4-
constructor(options: {
5-
url?: string
6-
headers?: { [key: string]: string }
7-
detectSessionInUrl?: boolean
8-
autoRefreshToken?: boolean
9-
persistSession?: boolean
10-
localStorage?: Storage
11-
}) {
5+
constructor(options: SupabaseAuthClientOptions) {
126
super(options)
137
}
148
}

src/lib/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import { GoTrueClient } from '@supabase/gotrue-js'
12
import { RealtimeClientOptions } from '@supabase/realtime-js'
23

4+
type GoTrueClientOptions = ConstructorParameters<typeof GoTrueClient>[0]
5+
6+
export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}
7+
38
export type SupabaseClientOptions = {
49
/**
510
* The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to 'public'.
@@ -24,7 +29,7 @@ export type SupabaseClientOptions = {
2429
/**
2530
* A storage provider. Used to store the logged in session.
2631
*/
27-
localStorage?: Storage
32+
localStorage?: SupabaseAuthClientOptions['localStorage']
2833

2934
/**
3035
* Options passed to the realtime-js instance

0 commit comments

Comments
 (0)