@insforge/sdk 1.0.5-dev.1 → 1.0.5-dev.2

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.mjs CHANGED
@@ -163,8 +163,6 @@ var TokenManager = class {
163
163
  this.user = null;
164
164
  // Mode: 'memory' (new backend) or 'storage' (legacy backend, default)
165
165
  this._mode = "storage";
166
- // Callback for token changes (used by realtime to reconnect with new token)
167
- this.onTokenChange = null;
168
166
  if (storage) {
169
167
  this.storage = storage;
170
168
  } else if (typeof window !== "undefined" && window.localStorage) {
@@ -225,16 +223,12 @@ var TokenManager = class {
225
223
  * Save session (memory always, localStorage only in storage mode)
226
224
  */
227
225
  saveSession(session) {
228
- const tokenChanged = session.accessToken !== this.accessToken;
229
226
  this.accessToken = session.accessToken;
230
227
  this.user = session.user;
231
228
  if (this._mode === "storage") {
232
229
  this.storage.setItem(TOKEN_KEY, session.accessToken);
233
230
  this.storage.setItem(USER_KEY, JSON.stringify(session.user));
234
231
  }
235
- if (tokenChanged && this.onTokenChange) {
236
- this.onTokenChange();
237
- }
238
232
  }
239
233
  /**
240
234
  * Get current session
@@ -258,14 +252,10 @@ var TokenManager = class {
258
252
  * Set access token
259
253
  */
260
254
  setAccessToken(token) {
261
- const tokenChanged = token !== this.accessToken;
262
255
  this.accessToken = token;
263
256
  if (this._mode === "storage") {
264
257
  this.storage.setItem(TOKEN_KEY, token);
265
258
  }
266
- if (tokenChanged && this.onTokenChange) {
267
- this.onTokenChange();
268
- }
269
259
  }
270
260
  /**
271
261
  * Get user
@@ -286,14 +276,10 @@ var TokenManager = class {
286
276
  * Clear session (both memory and localStorage)
287
277
  */
288
278
  clearSession() {
289
- const hadToken = this.accessToken !== null;
290
279
  this.accessToken = null;
291
280
  this.user = null;
292
281
  this.storage.removeItem(TOKEN_KEY);
293
282
  this.storage.removeItem(USER_KEY);
294
- if (hadToken && this.onTokenChange) {
295
- this.onTokenChange();
296
- }
297
283
  }
298
284
  /**
299
285
  * Check if there's a session in localStorage (for legacy detection)
@@ -680,6 +666,13 @@ var Auth = class {
680
666
  "/api/auth/profiles/current",
681
667
  { profile }
682
668
  );
669
+ const currentUser = this.tokenManager.getUser();
670
+ if (currentUser && response.profile !== void 0) {
671
+ this.tokenManager.setUser({
672
+ ...currentUser,
673
+ profile: response.profile
674
+ });
675
+ }
683
676
  return {
684
677
  data: response,
685
678
  error: null
@@ -1475,15 +1468,13 @@ var Functions = class {
1475
1468
  import { io } from "socket.io-client";
1476
1469
  var CONNECT_TIMEOUT = 1e4;
1477
1470
  var Realtime = class {
1478
- constructor(baseUrl, tokenManager, anonKey) {
1471
+ constructor(baseUrl, tokenManager) {
1479
1472
  this.socket = null;
1480
1473
  this.connectPromise = null;
1481
1474
  this.subscribedChannels = /* @__PURE__ */ new Set();
1482
1475
  this.eventListeners = /* @__PURE__ */ new Map();
1483
1476
  this.baseUrl = baseUrl;
1484
1477
  this.tokenManager = tokenManager;
1485
- this.anonKey = anonKey;
1486
- this.tokenManager.onTokenChange = () => this.onTokenChange();
1487
1478
  }
1488
1479
  notifyListeners(event, payload) {
1489
1480
  const listeners = this.eventListeners.get(event);
@@ -1509,7 +1500,7 @@ var Realtime = class {
1509
1500
  }
1510
1501
  this.connectPromise = new Promise((resolve, reject) => {
1511
1502
  const session = this.tokenManager.getSession();
1512
- const token = session?.accessToken ?? this.anonKey;
1503
+ const token = session?.accessToken;
1513
1504
  this.socket = io(this.baseUrl, {
1514
1505
  transports: ["websocket"],
1515
1506
  auth: token ? { token } : void 0
@@ -1575,22 +1566,6 @@ var Realtime = class {
1575
1566
  }
1576
1567
  this.subscribedChannels.clear();
1577
1568
  }
1578
- /**
1579
- * Handle token changes (e.g., after auth refresh)
1580
- * Updates socket auth so reconnects use the new token
1581
- * If connected, triggers reconnect to apply new token immediately
1582
- */
1583
- onTokenChange() {
1584
- const session = this.tokenManager.getSession();
1585
- const token = session?.accessToken ?? this.anonKey;
1586
- if (this.socket) {
1587
- this.socket.auth = token ? { token } : {};
1588
- }
1589
- if (this.socket?.connected) {
1590
- this.socket.disconnect();
1591
- this.socket.connect();
1592
- }
1593
- }
1594
1569
  /**
1595
1570
  * Check if connected to the realtime server
1596
1571
  */
@@ -1767,7 +1742,7 @@ var InsForgeClient = class {
1767
1742
  this.storage = new Storage(this.http);
1768
1743
  this.ai = new AI(this.http);
1769
1744
  this.functions = new Functions(this.http);
1770
- this.realtime = new Realtime(this.http.baseUrl, this.tokenManager, config.anonKey);
1745
+ this.realtime = new Realtime(this.http.baseUrl, this.tokenManager);
1771
1746
  this.emails = new Emails(this.http);
1772
1747
  }
1773
1748
  /**