Skip to content

Commit 2fd8785

Browse files
committed
fix(supabase): use direct GoTrueClientOptions import
1 parent 002886a commit 2fd8785

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

packages/core/auth-js/src/GoTrueClient.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,13 @@ export default class GoTrueClient {
381381
this.initialize()
382382
}
383383

384+
/**
385+
* Returns whether error throwing mode is enabled for this client.
386+
*/
387+
public isThrowOnErrorEnabled(): boolean {
388+
return this.throwOnError
389+
}
390+
384391
/**
385392
* Centralizes return handling with optional error throwing. When `throwOnError` is enabled
386393
* and the provided result contains a non-nullish error, the error is thrown instead of

packages/core/supabase-js/src/SupabaseClient.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ export default class SupabaseClient<
340340
flowType,
341341
lock,
342342
debug,
343+
throwOnError,
343344
}: SupabaseAuthClientOptions,
344345
headers?: Record<string, string>,
345346
fetch?: Fetch
@@ -360,6 +361,7 @@ export default class SupabaseClient<
360361
flowType,
361362
lock,
362363
debug,
364+
throwOnError,
363365
fetch,
364366
// auth checks if there is a custom authorizaiton header using this flag
365367
// so it knows whether to return an error when getUser is called with no session

packages/core/supabase-js/src/lib/types.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthClient } from '@supabase/auth-js'
1+
import { GoTrueClientOptions } from '@supabase/auth-js'
22
import { RealtimeClientOptions } from '@supabase/realtime-js'
33
import { PostgrestError } from '@supabase/postgrest-js'
44
import type { StorageClientOptions } from '@supabase/storage-js'
@@ -21,9 +21,7 @@ export type {
2121
GenericFunction,
2222
}
2323

24-
type AuthClientOptions = ConstructorParameters<typeof AuthClient>[0]
25-
26-
export interface SupabaseAuthClientOptions extends AuthClientOptions {}
24+
export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}
2725

2826
export type Fetch = typeof fetch
2927

@@ -78,6 +76,11 @@ export type SupabaseClientOptions<SchemaName> = {
7876
* @experimental
7977
*/
8078
lock?: SupabaseAuthClientOptions['lock']
79+
/**
80+
* If there is an error with the query, throwOnError will reject the promise by
81+
* throwing the error instead of returning it as part of a successful response.
82+
*/
83+
throwOnError?: SupabaseAuthClientOptions['throwOnError']
8184
}
8285
/**
8386
* Options passed to the realtime-js instance

packages/core/supabase-js/test/unit/SupabaseAuthClient.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,21 @@ test('_initSupabaseAuthClient should overwrite authHeaders if headers are provid
3333
expect(authClient['headers']['Authorization']).toBe('Bearer custom-auth-header')
3434
expect(authClient['headers']['apikey']).toBe('supabaseKey')
3535
})
36+
37+
test('_initSupabaseAuthClient should pass through throwOnError option', () => {
38+
const client = new SupabaseClient('https://example.supabase.com', 'supabaseKey')
39+
const authClient = client['_initSupabaseAuthClient'](
40+
{ ...authSettings, throwOnError: true },
41+
undefined,
42+
undefined
43+
)
44+
45+
expect((authClient as any).isThrowOnErrorEnabled()).toBe(true)
46+
})
47+
48+
test('createClient should accept auth.throwOnError and wire it to auth client', () => {
49+
const supa = new SupabaseClient('https://example.supabase.com', 'supabaseKey', {
50+
auth: { throwOnError: true },
51+
})
52+
expect((supa.auth as any).isThrowOnErrorEnabled()).toBe(true)
53+
})

0 commit comments

Comments
 (0)