@supabase/auth-js 2.106.2-canary.1 → 2.107.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +11 -0
- package/dist/main/GoTrueClient.d.ts +68 -14
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +331 -107
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/lib/errors.d.ts +24 -0
- package/dist/main/lib/errors.d.ts.map +1 -1
- package/dist/main/lib/errors.js +31 -1
- package/dist/main/lib/errors.js.map +1 -1
- package/dist/main/lib/locks.d.ts +28 -34
- package/dist/main/lib/locks.d.ts.map +1 -1
- package/dist/main/lib/locks.js +28 -34
- package/dist/main/lib/locks.js.map +1 -1
- package/dist/main/lib/types.d.ts +16 -27
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/types.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/version.js.map +1 -1
- package/dist/module/GoTrueClient.d.ts +68 -14
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +333 -109
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/lib/errors.d.ts +24 -0
- package/dist/module/lib/errors.d.ts.map +1 -1
- package/dist/module/lib/errors.js +28 -0
- package/dist/module/lib/errors.js.map +1 -1
- package/dist/module/lib/locks.d.ts +28 -34
- package/dist/module/lib/locks.d.ts.map +1 -1
- package/dist/module/lib/locks.js +28 -34
- package/dist/module/lib/locks.js.map +1 -1
- package/dist/module/lib/types.d.ts +16 -27
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/types.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/version.js.map +1 -1
- package/dist/tsconfig.module.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/README.md +25 -0
- package/migrations/lockless-coordination.md +89 -0
- package/package.json +4 -2
- package/src/GoTrueClient.ts +397 -137
- package/src/lib/errors.ts +32 -0
- package/src/lib/locks.ts +29 -34
- package/src/lib/types.ts +16 -27
- package/src/lib/version.ts +1 -1
package/src/lib/errors.ts
CHANGED
|
@@ -297,6 +297,38 @@ export function isAuthRetryableFetchError(error: unknown): error is AuthRetryabl
|
|
|
297
297
|
return isAuthError(error) && error.name === 'AuthRetryableFetchError'
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
/**
|
|
301
|
+
* Returned when the server rotated a refresh token successfully but the
|
|
302
|
+
* client chose not to persist the rotated tokens because the local session
|
|
303
|
+
* changed mid-flight. Usually means a concurrent `signOut` cleared storage
|
|
304
|
+
* between when the refresh started and when it came back.
|
|
305
|
+
*
|
|
306
|
+
* Set on the `error` field of the refresh result so callers can tell "we
|
|
307
|
+
* got rotated tokens but threw them away" apart from "the refresh failed."
|
|
308
|
+
* The rotated session on the server will be picked up on the next refresh
|
|
309
|
+
* via GoTrue's parent-of-active path.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* import { isAuthRefreshDiscardedError } from '@supabase/auth-js'
|
|
314
|
+
*
|
|
315
|
+
* if (isAuthRefreshDiscardedError(error)) {
|
|
316
|
+
* // Concurrent signOut/sign-in raced our refresh. Treat as a no-op.
|
|
317
|
+
* }
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export class AuthRefreshDiscardedError extends CustomAuthError {
|
|
321
|
+
constructor(
|
|
322
|
+
message = 'Refresh result discarded: session state changed mid-flight (e.g., concurrent signOut)'
|
|
323
|
+
) {
|
|
324
|
+
super(message, 'AuthRefreshDiscardedError', 409, undefined)
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function isAuthRefreshDiscardedError(error: unknown): error is AuthRefreshDiscardedError {
|
|
329
|
+
return isAuthError(error) && error.name === 'AuthRefreshDiscardedError'
|
|
330
|
+
}
|
|
331
|
+
|
|
300
332
|
/**
|
|
301
333
|
* This error is thrown on certain methods when the password used is deemed
|
|
302
334
|
* weak. Inspect the reasons to identify what password strength rules are
|
package/src/lib/locks.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lock primitives retained for backwards-compatible imports. The auth client
|
|
3
|
+
* coordinates refreshes itself (deduping in-instance callers onto a shared
|
|
4
|
+
* in-flight promise) and lets the GoTrue server resolve cross-instance races,
|
|
5
|
+
* so it does not invoke any primitive from this module. The functions still
|
|
6
|
+
* work for direct callers that need a navigator.locks-backed or in-process
|
|
7
|
+
* exclusive lock of their own.
|
|
8
|
+
*/
|
|
9
|
+
|
|
1
10
|
import { supportsLocalStorage } from './helpers'
|
|
2
11
|
|
|
3
12
|
/**
|
|
13
|
+
* @deprecated Debug flag for `navigatorLock` / `processLock`. The auth
|
|
14
|
+
* client ignores both, so this has no client-side effect.
|
|
4
15
|
* @experimental
|
|
5
16
|
*/
|
|
6
17
|
export const internals = {
|
|
@@ -18,18 +29,9 @@ export const internals = {
|
|
|
18
29
|
/**
|
|
19
30
|
* An error thrown when a lock cannot be acquired after some amount of time.
|
|
20
31
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* ```ts
|
|
25
|
-
* import { LockAcquireTimeoutError } from '@supabase/auth-js'
|
|
26
|
-
*
|
|
27
|
-
* class CustomLockError extends LockAcquireTimeoutError {
|
|
28
|
-
* constructor() {
|
|
29
|
-
* super('Lock timed out')
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
32
|
+
* @deprecated The auth client doesn't acquire locks around auth operations,
|
|
33
|
+
* so this error never originates from `supabase.auth.*` calls. Direct callers
|
|
34
|
+
* of `navigatorLock` / `processLock` still receive it on acquire timeout.
|
|
33
35
|
*/
|
|
34
36
|
export abstract class LockAcquireTimeoutError extends Error {
|
|
35
37
|
public readonly isAcquireTimeout = true
|
|
@@ -40,25 +42,15 @@ export abstract class LockAcquireTimeoutError extends Error {
|
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* ```ts
|
|
47
|
-
* import { NavigatorLockAcquireTimeoutError } from '@supabase/auth-js'
|
|
48
|
-
*
|
|
49
|
-
* throw new NavigatorLockAcquireTimeoutError('Lock timed out')
|
|
50
|
-
* ```
|
|
45
|
+
* @deprecated The auth client doesn't call `navigator.locks`, so this error
|
|
46
|
+
* never originates from `supabase.auth.*` calls. Direct callers of
|
|
47
|
+
* `navigatorLock` still receive it on acquire timeout.
|
|
51
48
|
*/
|
|
52
49
|
export class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {}
|
|
53
50
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* import { ProcessLockAcquireTimeoutError } from '@supabase/auth-js'
|
|
59
|
-
*
|
|
60
|
-
* throw new ProcessLockAcquireTimeoutError('Lock timed out')
|
|
61
|
-
* ```
|
|
51
|
+
* @deprecated The auth client doesn't run `processLock`, so this error
|
|
52
|
+
* never originates from `supabase.auth.*` calls. Direct callers of
|
|
53
|
+
* `processLock` still receive it on acquire timeout.
|
|
62
54
|
*/
|
|
63
55
|
export class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {}
|
|
64
56
|
|
|
@@ -86,12 +78,10 @@ export class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {}
|
|
|
86
78
|
* will time out after so many milliseconds. An error is
|
|
87
79
|
* a timeout if it has `isAcquireTimeout` set to true.
|
|
88
80
|
* @param fn The operation to run once the lock is acquired.
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* })
|
|
94
|
-
* ```
|
|
81
|
+
*
|
|
82
|
+
* @deprecated The auth client coordinates refreshes itself and the server
|
|
83
|
+
* resolves concurrent refresh races, so passing `{ lock: navigatorLock }`
|
|
84
|
+
* to it has no effect. You can safely drop the import from your client setup.
|
|
95
85
|
*/
|
|
96
86
|
export async function navigatorLock<R>(
|
|
97
87
|
name: string,
|
|
@@ -320,6 +310,11 @@ const PROCESS_LOCKS: { [name: string]: Promise<any> } = {}
|
|
|
320
310
|
* will time out after so many milliseconds. An error is
|
|
321
311
|
* a timeout if it has `isAcquireTimeout` set to true.
|
|
322
312
|
* @param fn The operation to run once the lock is acquired.
|
|
313
|
+
*
|
|
314
|
+
* @deprecated The auth client coordinates refreshes itself and the server
|
|
315
|
+
* resolves concurrent refresh races, so passing `{ lock: processLock }`
|
|
316
|
+
* to it has no effect. You can safely drop the import from your client setup.
|
|
317
|
+
*
|
|
323
318
|
* @example
|
|
324
319
|
* ```ts
|
|
325
320
|
* await processLock('migrate', 5000, async () => {
|
package/src/lib/types.ts
CHANGED
|
@@ -126,12 +126,17 @@ export type GoTrueClientOptions = {
|
|
|
126
126
|
/* If debug messages are emitted. Can be used to inspect the behavior of the library. If set to a function, the provided function will be used instead of `console.log()` to perform the logging. */
|
|
127
127
|
debug?: boolean | ((message: string, ...args: any[]) => void)
|
|
128
128
|
/**
|
|
129
|
-
* Provide your own locking mechanism based on the environment. By default
|
|
130
|
-
*
|
|
131
|
-
* `
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
129
|
+
* Provide your own locking mechanism based on the environment. By default
|
|
130
|
+
* the client coordinates refreshes itself (single-flight via
|
|
131
|
+
* `refreshingDeferred` + commit guard) and relies on the GoTrue server to
|
|
132
|
+
* resolve cross-tab refresh races. Passing a custom lock opts into a
|
|
133
|
+
* legacy path that wraps every auth operation in your supplied lock — this
|
|
134
|
+
* path is preserved for backwards compatibility (typically React Native
|
|
135
|
+
* `processLock` or Node multi-process setups).
|
|
136
|
+
*
|
|
137
|
+
* @deprecated Custom locks still work in v2.x for backwards compatibility.
|
|
138
|
+
* The legacy lock path will be removed in v3 — drop this option from your
|
|
139
|
+
* constructor options before upgrading.
|
|
135
140
|
*/
|
|
136
141
|
lock?: LockFunc
|
|
137
142
|
/**
|
|
@@ -145,30 +150,14 @@ export type GoTrueClientOptions = {
|
|
|
145
150
|
*/
|
|
146
151
|
throwOnError?: boolean
|
|
147
152
|
/**
|
|
148
|
-
* The maximum time in milliseconds to wait for acquiring
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* via the Web Locks API to prevent race conditions during session refresh and other operations.
|
|
152
|
-
* This timeout controls how long to wait before attempting lock recovery.
|
|
153
|
-
*
|
|
154
|
-
* - **Positive value**: Wait up to this many milliseconds. If the lock is still held, attempt
|
|
155
|
-
* automatic recovery by stealing it (the previous holder is evicted, its callback continues
|
|
156
|
-
* to completion without exclusive access). This recovers from orphaned locks caused by
|
|
157
|
-
* React Strict Mode double-mount, storage API hangs, or aborted operations.
|
|
158
|
-
* - **Zero (0)**: Fail immediately if the lock is unavailable; throws `LockAcquireTimeoutError`
|
|
159
|
-
* (check `error.isAcquireTimeout === true`).
|
|
160
|
-
* - **Negative value**: Wait indefinitely — can cause permanent deadlocks if the lock is orphaned.
|
|
153
|
+
* The maximum time in milliseconds to wait for acquiring the custom lock
|
|
154
|
+
* supplied via the `lock` option. Only consulted when a custom `lock` is
|
|
155
|
+
* passed — the default lockless path doesn't use this timeout.
|
|
161
156
|
*
|
|
162
157
|
* @default 5000
|
|
163
158
|
*
|
|
164
|
-
* @
|
|
165
|
-
*
|
|
166
|
-
* const client = createClient(url, key, {
|
|
167
|
-
* auth: {
|
|
168
|
-
* lockAcquireTimeout: 5000, // 5 seconds, then steal orphaned lock
|
|
169
|
-
* },
|
|
170
|
-
* })
|
|
171
|
-
* ```
|
|
159
|
+
* @deprecated Only used by the legacy lock path. Will be removed in v3
|
|
160
|
+
* along with the `lock` option.
|
|
172
161
|
*/
|
|
173
162
|
lockAcquireTimeout?: number
|
|
174
163
|
|
package/src/lib/version.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// - Debugging and support (identifying which version is running)
|
|
5
5
|
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
6
|
// - Ensuring build artifacts match the published package version
|
|
7
|
-
export const version = '2.
|
|
7
|
+
export const version = '2.107.0-beta.0'
|