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/esm/index.js CHANGED
@@ -5704,6 +5704,27 @@ var Storage = /** @class */ (function () {
5704
5704
  }
5705
5705
  return null;
5706
5706
  };
5707
+ Storage.setTokenExpiry = function (expiresInSeconds) {
5708
+ var expiryTime = Date.now() + (expiresInSeconds * 1000);
5709
+ Storage.set('glitch_token_expiry', expiryTime);
5710
+ // Also set a cookie for cross-subdomain consistency if rootDomain exists
5711
+ if (Storage.rootDomain && typeof document !== 'undefined') {
5712
+ this.setCookie('glitch_token_expiry', expiryTime.toString(), 31);
5713
+ }
5714
+ };
5715
+ Storage.getTokenExpiry = function () {
5716
+ var expiry = Storage.getCookie('glitch_token_expiry');
5717
+ if (!expiry) {
5718
+ expiry = Storage.get('glitch_token_expiry');
5719
+ }
5720
+ return expiry ? parseInt(expiry) : null;
5721
+ };
5722
+ Storage.isTokenExpired = function () {
5723
+ var expiry = this.getTokenExpiry();
5724
+ if (!expiry)
5725
+ return false; // If no expiry set, assume valid or let API handle 401
5726
+ return Date.now() > expiry;
5727
+ };
5707
5728
  Storage.rootDomain = '';
5708
5729
  Storage.data = {};
5709
5730
  return Storage;
@@ -17146,6 +17167,11 @@ var Session = /** @class */ (function () {
17146
17167
  }
17147
17168
  Session.isLoggedIn = function () {
17148
17169
  var authToken = Storage.getAuthToken();
17170
+ var expired = Storage.isTokenExpired();
17171
+ if (expired) {
17172
+ Session.end(); // Auto-clear if expired
17173
+ return false;
17174
+ }
17149
17175
  return authToken !== null && authToken !== 'null' && authToken !== undefined;
17150
17176
  };
17151
17177
  Session.getAuthToken = function () {
@@ -17169,6 +17195,8 @@ var Session = /** @class */ (function () {
17169
17195
  };
17170
17196
  Session.end = function () {
17171
17197
  Storage.setAuthToken(null);
17198
+ Storage.set('glitch_token_expiry', null); // Clear expiry
17199
+ Storage.eraseCookie('glitch_token_expiry');
17172
17200
  Storage.set(Session._id_key, null);
17173
17201
  Storage.set(Session._first_name_key, null);
17174
17202
  Storage.set(Session._last_name_key, null);
@@ -17177,6 +17205,7 @@ var Session = /** @class */ (function () {
17177
17205
  };
17178
17206
  Session.processAuthentication = function (data) {
17179
17207
  Storage.setAuthToken(data.token.access_token);
17208
+ Storage.setTokenExpiry(data.token.expires_in); // Save the timeout
17180
17209
  Storage.set(Session._id_key, data.id);
17181
17210
  Storage.set(Session._first_name_key, data.first_name);
17182
17211
  Storage.set(Session._last_name_key, data.last_name);