@insforge/sdk 1.0.5-dev.0 → 1.0.5-dev.1
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/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -105,6 +105,7 @@ declare class TokenManager {
|
|
|
105
105
|
private user;
|
|
106
106
|
private storage;
|
|
107
107
|
private _mode;
|
|
108
|
+
onTokenChange: (() => void) | null;
|
|
108
109
|
constructor(storage?: TokenStorage);
|
|
109
110
|
/**
|
|
110
111
|
* Get current mode
|
|
@@ -670,6 +671,12 @@ declare class Realtime {
|
|
|
670
671
|
* Disconnect from the realtime server
|
|
671
672
|
*/
|
|
672
673
|
disconnect(): void;
|
|
674
|
+
/**
|
|
675
|
+
* Handle token changes (e.g., after auth refresh)
|
|
676
|
+
* Updates socket auth so reconnects use the new token
|
|
677
|
+
* If connected, triggers reconnect to apply new token immediately
|
|
678
|
+
*/
|
|
679
|
+
private onTokenChange;
|
|
673
680
|
/**
|
|
674
681
|
* Check if connected to the realtime server
|
|
675
682
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ declare class TokenManager {
|
|
|
105
105
|
private user;
|
|
106
106
|
private storage;
|
|
107
107
|
private _mode;
|
|
108
|
+
onTokenChange: (() => void) | null;
|
|
108
109
|
constructor(storage?: TokenStorage);
|
|
109
110
|
/**
|
|
110
111
|
* Get current mode
|
|
@@ -670,6 +671,12 @@ declare class Realtime {
|
|
|
670
671
|
* Disconnect from the realtime server
|
|
671
672
|
*/
|
|
672
673
|
disconnect(): void;
|
|
674
|
+
/**
|
|
675
|
+
* Handle token changes (e.g., after auth refresh)
|
|
676
|
+
* Updates socket auth so reconnects use the new token
|
|
677
|
+
* If connected, triggers reconnect to apply new token immediately
|
|
678
|
+
*/
|
|
679
|
+
private onTokenChange;
|
|
673
680
|
/**
|
|
674
681
|
* Check if connected to the realtime server
|
|
675
682
|
*/
|
package/dist/index.js
CHANGED
|
@@ -202,6 +202,8 @@ var TokenManager = class {
|
|
|
202
202
|
this.user = null;
|
|
203
203
|
// Mode: 'memory' (new backend) or 'storage' (legacy backend, default)
|
|
204
204
|
this._mode = "storage";
|
|
205
|
+
// Callback for token changes (used by realtime to reconnect with new token)
|
|
206
|
+
this.onTokenChange = null;
|
|
205
207
|
if (storage) {
|
|
206
208
|
this.storage = storage;
|
|
207
209
|
} else if (typeof window !== "undefined" && window.localStorage) {
|
|
@@ -262,12 +264,16 @@ var TokenManager = class {
|
|
|
262
264
|
* Save session (memory always, localStorage only in storage mode)
|
|
263
265
|
*/
|
|
264
266
|
saveSession(session) {
|
|
267
|
+
const tokenChanged = session.accessToken !== this.accessToken;
|
|
265
268
|
this.accessToken = session.accessToken;
|
|
266
269
|
this.user = session.user;
|
|
267
270
|
if (this._mode === "storage") {
|
|
268
271
|
this.storage.setItem(TOKEN_KEY, session.accessToken);
|
|
269
272
|
this.storage.setItem(USER_KEY, JSON.stringify(session.user));
|
|
270
273
|
}
|
|
274
|
+
if (tokenChanged && this.onTokenChange) {
|
|
275
|
+
this.onTokenChange();
|
|
276
|
+
}
|
|
271
277
|
}
|
|
272
278
|
/**
|
|
273
279
|
* Get current session
|
|
@@ -291,10 +297,14 @@ var TokenManager = class {
|
|
|
291
297
|
* Set access token
|
|
292
298
|
*/
|
|
293
299
|
setAccessToken(token) {
|
|
300
|
+
const tokenChanged = token !== this.accessToken;
|
|
294
301
|
this.accessToken = token;
|
|
295
302
|
if (this._mode === "storage") {
|
|
296
303
|
this.storage.setItem(TOKEN_KEY, token);
|
|
297
304
|
}
|
|
305
|
+
if (tokenChanged && this.onTokenChange) {
|
|
306
|
+
this.onTokenChange();
|
|
307
|
+
}
|
|
298
308
|
}
|
|
299
309
|
/**
|
|
300
310
|
* Get user
|
|
@@ -315,10 +325,14 @@ var TokenManager = class {
|
|
|
315
325
|
* Clear session (both memory and localStorage)
|
|
316
326
|
*/
|
|
317
327
|
clearSession() {
|
|
328
|
+
const hadToken = this.accessToken !== null;
|
|
318
329
|
this.accessToken = null;
|
|
319
330
|
this.user = null;
|
|
320
331
|
this.storage.removeItem(TOKEN_KEY);
|
|
321
332
|
this.storage.removeItem(USER_KEY);
|
|
333
|
+
if (hadToken && this.onTokenChange) {
|
|
334
|
+
this.onTokenChange();
|
|
335
|
+
}
|
|
322
336
|
}
|
|
323
337
|
/**
|
|
324
338
|
* Check if there's a session in localStorage (for legacy detection)
|
|
@@ -1508,6 +1522,7 @@ var Realtime = class {
|
|
|
1508
1522
|
this.baseUrl = baseUrl;
|
|
1509
1523
|
this.tokenManager = tokenManager;
|
|
1510
1524
|
this.anonKey = anonKey;
|
|
1525
|
+
this.tokenManager.onTokenChange = () => this.onTokenChange();
|
|
1511
1526
|
}
|
|
1512
1527
|
notifyListeners(event, payload) {
|
|
1513
1528
|
const listeners = this.eventListeners.get(event);
|
|
@@ -1599,6 +1614,22 @@ var Realtime = class {
|
|
|
1599
1614
|
}
|
|
1600
1615
|
this.subscribedChannels.clear();
|
|
1601
1616
|
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Handle token changes (e.g., after auth refresh)
|
|
1619
|
+
* Updates socket auth so reconnects use the new token
|
|
1620
|
+
* If connected, triggers reconnect to apply new token immediately
|
|
1621
|
+
*/
|
|
1622
|
+
onTokenChange() {
|
|
1623
|
+
const session = this.tokenManager.getSession();
|
|
1624
|
+
const token = session?.accessToken ?? this.anonKey;
|
|
1625
|
+
if (this.socket) {
|
|
1626
|
+
this.socket.auth = token ? { token } : {};
|
|
1627
|
+
}
|
|
1628
|
+
if (this.socket?.connected) {
|
|
1629
|
+
this.socket.disconnect();
|
|
1630
|
+
this.socket.connect();
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1602
1633
|
/**
|
|
1603
1634
|
* Check if connected to the realtime server
|
|
1604
1635
|
*/
|