glitch-javascript-sdk 2.6.7 → 2.6.8

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/cjs/index.js CHANGED
@@ -18888,6 +18888,27 @@ var Storage = /** @class */ (function () {
18888
18888
  }
18889
18889
  return null;
18890
18890
  };
18891
+ Storage.setTokenExpiry = function (expiresInSeconds) {
18892
+ var expiryTime = Date.now() + (expiresInSeconds * 1000);
18893
+ Storage.set('glitch_token_expiry', expiryTime);
18894
+ // Also set a cookie for cross-subdomain consistency if rootDomain exists
18895
+ if (Storage.rootDomain && typeof document !== 'undefined') {
18896
+ this.setCookie('glitch_token_expiry', expiryTime.toString(), 31);
18897
+ }
18898
+ };
18899
+ Storage.getTokenExpiry = function () {
18900
+ var expiry = Storage.getCookie('glitch_token_expiry');
18901
+ if (!expiry) {
18902
+ expiry = Storage.get('glitch_token_expiry');
18903
+ }
18904
+ return expiry ? parseInt(expiry) : null;
18905
+ };
18906
+ Storage.isTokenExpired = function () {
18907
+ var expiry = this.getTokenExpiry();
18908
+ if (!expiry)
18909
+ return false; // If no expiry set, assume valid or let API handle 401
18910
+ return Date.now() > expiry;
18911
+ };
18891
18912
  Storage.rootDomain = '';
18892
18913
  Storage.data = {};
18893
18914
  return Storage;
@@ -30330,6 +30351,11 @@ var Session = /** @class */ (function () {
30330
30351
  }
30331
30352
  Session.isLoggedIn = function () {
30332
30353
  var authToken = Storage.getAuthToken();
30354
+ var expired = Storage.isTokenExpired();
30355
+ if (expired) {
30356
+ Session.end(); // Auto-clear if expired
30357
+ return false;
30358
+ }
30333
30359
  return authToken !== null && authToken !== 'null' && authToken !== undefined;
30334
30360
  };
30335
30361
  Session.getAuthToken = function () {
@@ -30353,6 +30379,8 @@ var Session = /** @class */ (function () {
30353
30379
  };
30354
30380
  Session.end = function () {
30355
30381
  Storage.setAuthToken(null);
30382
+ Storage.set('glitch_token_expiry', null); // Clear expiry
30383
+ Storage.eraseCookie('glitch_token_expiry');
30356
30384
  Storage.set(Session._id_key, null);
30357
30385
  Storage.set(Session._first_name_key, null);
30358
30386
  Storage.set(Session._last_name_key, null);
@@ -30361,6 +30389,7 @@ var Session = /** @class */ (function () {
30361
30389
  };
30362
30390
  Session.processAuthentication = function (data) {
30363
30391
  Storage.setAuthToken(data.token.access_token);
30392
+ Storage.setTokenExpiry(data.token.expires_in); // Save the timeout
30364
30393
  Storage.set(Session._id_key, data.id);
30365
30394
  Storage.set(Session._first_name_key, data.first_name);
30366
30395
  Storage.set(Session._last_name_key, data.last_name);