supaapps-auth 3.2.0 → 3.2.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.d.ts CHANGED
@@ -42,6 +42,7 @@ declare enum Platforms {
42
42
 
43
43
  declare class AuthManager {
44
44
  private static instance;
45
+ private readonly tokenExpiryLeewaySeconds;
45
46
  private authServer;
46
47
  private realmName;
47
48
  private redirectUri;
package/dist/index.js CHANGED
@@ -68,6 +68,7 @@ function generateCodeChallenge(verifier) {
68
68
  // src/AuthManager.ts
69
69
  var AuthManager = class _AuthManager {
70
70
  static instance = null;
71
+ tokenExpiryLeewaySeconds = 10;
71
72
  authServer;
72
73
  realmName;
73
74
  redirectUri;
@@ -141,13 +142,17 @@ var AuthManager = class _AuthManager {
141
142
  async checkAccessToken(isInitilization = false) {
142
143
  const accessToken = localStorage.getItem("access_token");
143
144
  if (accessToken && this.isTokenExpired(accessToken)) {
145
+ console.info(
146
+ "[AuthManager] Access token expired or near expiry; refreshing."
147
+ );
144
148
  return this.refreshAccessToken(isInitilization);
145
149
  }
146
150
  return accessToken;
147
151
  }
148
152
  isTokenExpired(token) {
149
153
  const decoded = this.tokenToPayload(token);
150
- return decoded.exp < Date.now() / 1e3;
154
+ const nowSeconds = Date.now() / 1e3;
155
+ return decoded.exp <= nowSeconds + this.tokenExpiryLeewaySeconds;
151
156
  }
152
157
  async mustBeLoggedIn() {
153
158
  if (!await this.isLoggedIn()) {
@@ -168,6 +173,9 @@ var AuthManager = class _AuthManager {
168
173
  }
169
174
  if (this.isTokenExpired(accessToken)) {
170
175
  try {
176
+ console.info(
177
+ "[AuthManager] Access token expired or near expiry; refreshing."
178
+ );
171
179
  await this.refreshAccessToken();
172
180
  return true;
173
181
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supaapps-auth",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",