Skip to content

Commit 1be080f

Browse files
committed
docs(auth): update docs and add todos for v3
1 parent c4fe717 commit 1be080f

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import {
5353
validateExp,
5454
} from './lib/helpers'
5555
import { memoryLocalStorageAdapter } from './lib/local-storage'
56-
import { LockAcquireTimeoutError, navigatorLock, processLock } from './lib/locks'
56+
import { LockAcquireTimeoutError, processLock } from './lib/locks'
5757
import { polyfillGlobalThis } from './lib/polyfills'
5858
import { version } from './lib/version'
5959

@@ -2536,7 +2536,7 @@ export default class GoTrueClient {
25362536
* - If the session's access token is expired or is about to expire, this method will use the refresh token to refresh the session.
25372537
* - When using in a browser, or you've called `startAutoRefresh()` in your environment (React Native, etc.) this function always returns a valid access token without refreshing the session itself, as this is done in the background. This function returns very fast.
25382538
* - **IMPORTANT SECURITY NOTICE:** If using an insecure storage medium, such as cookies or request headers, the user object returned by this function **must not be trusted**. Always verify the JWT using `getClaims()` or your own JWT verification library to securely establish the user's identity and access. You can also use `getUser()` to fetch the user object directly from the Auth server for this purpose.
2539-
* - When using in a browser, this function is synchronized across all tabs using the [LockManager](https://developer.mozilla.org/en-US/docs/Web/API/LockManager) API. In other environments make sure you've defined a proper `lock` property, if necessary, to make sure there are no race conditions while the session is being refreshed.
2539+
* - This function is synchronized within the current process using an in-process lock. Cross-tab refresh races are handled server-side by GoTrue's refresh token reuse detection. You can opt in to cross-tab serialization via the Web Locks API by passing `lock: navigatorLock` (deprecated) in the client options.
25402540
*
25412541
* @example Get the session data
25422542
* ```js

packages/core/auth-js/src/lib/locks.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ export abstract class LockAcquireTimeoutError extends Error {
4242
/**
4343
* Error thrown when the browser Navigator Lock API fails to acquire a lock.
4444
*
45-
* @example
46-
* ```ts
47-
* import { NavigatorLockAcquireTimeoutError } from '@supabase/auth-js'
45+
* @deprecated Only thrown by the deprecated {@link navigatorLock}. Scheduled
46+
* for removal in the next major version. Use {@link ProcessLockAcquireTimeoutError}
47+
* or catch {@link LockAcquireTimeoutError} instead.
4848
*
49-
* throw new NavigatorLockAcquireTimeoutError('Lock timed out')
50-
* ```
49+
* TODO(v3): remove along with navigatorLock.
5150
*/
5251
export class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {}
5352
/**
@@ -69,6 +68,14 @@ export class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {}
6968
* throw. Make sure you check availablility before configuring {@link
7069
* GoTrueClient}.
7170
*
71+
* @deprecated `navigatorLock` is no longer the default browser lock and is kept
72+
* only for opt-in use. It is scheduled for removal in the next major version.
73+
* The default `processLock` handles within-tab serialization, and cross-tab
74+
* refresh races are handled server-side by GoTrue's refresh token reuse
75+
* detection. To opt in: `createClient(url, key, { auth: { lock: navigatorLock } })`
76+
*
77+
* TODO(v3): remove navigatorLock export and all steal-based recovery logic.
78+
*
7279
* You can turn on debugging by setting the `supabase.gotrue-js.locks.debug`
7380
* local storage item to `true`.
7481
*
@@ -305,7 +312,8 @@ const PROCESS_LOCKS: { [name: string]: Promise<any> } = {}
305312
* Useful for environments like React Native or other non-browser
306313
* single-process (i.e. no concept of "tabs") environments.
307314
*
308-
* Use {@link #navigatorLock} in browser environments.
315+
* This is the default lock for all environments. Use {@link navigatorLock} only
316+
* if you need opt-in cross-tab serialization via the Web Locks API.
309317
*
310318
* @param name Name of the lock to be acquired.
311319
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,16 @@ export type GoTrueClientOptions = {
124124
* `processLock` (an in-process queue) is used in browser environments when
125125
* `persistSession` is true. Falls back to a no-op for non-browser environments.
126126
*
127-
* To opt back in to the Web Locks API for cross-tab serialization:
127+
* Cross-tab token refresh races are handled server-side: GoTrue allows
128+
* concurrent refreshes of the same token (via reuse detection) so both tabs
129+
* receive valid tokens without any client-side coordination.
130+
*
131+
* To opt back in to the Web Locks API for explicit cross-tab serialization
132+
* (deprecated, scheduled for removal in the next major version):
128133
* ```ts
129134
* import { navigatorLock } from '@supabase/auth-js'
130135
* createClient(url, key, { auth: { lock: navigatorLock } })
131136
* ```
132-
*
133-
* @experimental
134137
*/
135138
lock?: LockFunc
136139
/**

0 commit comments

Comments
 (0)