Skip to content

Commit 864f310

Browse files
thomasballingerConvex, Inc.
authored and
Convex, Inc.
committed
Make disable in ConvexClient apply to setAuth (#37065)
GitOrigin-RevId: 254c09ce51837ce8a61b717e7faac7cb45f1611f
1 parent 3d7100d commit 864f310

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/browser/simple_client.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class ConvexClient {
7878
| ReturnType<typeof setTimeout>
7979
| undefined;
8080
private _closed: boolean;
81-
disabled: boolean;
81+
private _disabled: boolean;
8282
/**
8383
* Once closed no registered callbacks will fire again.
8484
*/
@@ -89,6 +89,9 @@ export class ConvexClient {
8989
if (this._client) return this._client;
9090
throw new Error("ConvexClient is disabled");
9191
}
92+
get disabled(): boolean {
93+
return this._disabled;
94+
}
9295

9396
/**
9497
* Construct a client and immediately initiate a WebSocket connection to the passed address.
@@ -101,7 +104,7 @@ export class ConvexClient {
101104
}
102105
const { disabled, ...baseOptions } = options;
103106
this._closed = false;
104-
this.disabled = !!disabled;
107+
this._disabled = !!disabled;
105108
if (
106109
defaultWebSocketConstructor &&
107110
!("webSocketConstructor" in baseOptions) &&
@@ -254,13 +257,14 @@ export class ConvexClient {
254257
* `fetchToken` will be called automatically again if a token expires.
255258
* `fetchToken` should return `null` if the token cannot be retrieved, for example
256259
* when the user's rights were permanently revoked.
257-
* @param fetchToken - an async function returning the JWT-encoded OpenID Connect Identity Token
260+
* @param fetchToken - an async function returning the JWT (typically an OpenID Connect Identity Token)
258261
* @param onChange - a callback that will be called when the authentication status changes
259262
*/
260263
setAuth(
261264
fetchToken: AuthTokenFetcher,
262265
onChange?: (isAuthenticated: boolean) => void,
263266
) {
267+
if (this.disabled) return;
264268
this.client.setAuth(
265269
fetchToken,
266270
onChange ??

0 commit comments

Comments
 (0)