@payez/next-mvp 4.0.43 → 4.0.44

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.
@@ -183,12 +183,18 @@ class ApiHandler {
183
183
  }
184
184
  }
185
185
  catch { /* ignore */ }
186
- // Check if token needs refresh
187
- // Skip entirely if there's no refresh token nothing to refresh with
186
+ // Check if token needs refresh.
187
+ // Skip the optimization (hasRefreshToken check) when access token is missing
188
+ // some session shapes store the refresh token under different field names,
189
+ // and we still want a refresh attempt to populate the access token.
188
190
  const thresholdMs = 5 * 60 * 1000;
189
191
  const expires = sessionData.idpAccessTokenExpires || 0;
190
- const hasRefreshToken = !!sessionData.idpRefreshToken;
191
- const needsRefresh = hasRefreshToken && (!accessToken || (expires - Date.now()) <= thresholdMs);
192
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
193
+ const hasRefreshToken = !!(sessionData.idpRefreshToken || sessionData.refreshToken);
194
+ const accessTokenStale = !accessToken || (expires - Date.now()) <= thresholdMs;
195
+ // If we already have a fresh access token, skip refresh entirely (no lock).
196
+ // If we don't, only attempt refresh when we have a refresh token to use.
197
+ const needsRefresh = accessTokenStale && hasRefreshToken;
192
198
  if (needsRefresh) {
193
199
  const refreshResult = await this.handleCoordinatedRefresh(req, token, sessionData, ctx);
194
200
  if (refreshResult.blocked) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payez/next-mvp",
3
- "version": "4.0.43",
3
+ "version": "4.0.44",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -278,12 +278,18 @@ export class ApiHandler {
278
278
  }
279
279
  } catch { /* ignore */ }
280
280
 
281
- // Check if token needs refresh
282
- // Skip entirely if there's no refresh token nothing to refresh with
281
+ // Check if token needs refresh.
282
+ // Skip the optimization (hasRefreshToken check) when access token is missing
283
+ // some session shapes store the refresh token under different field names,
284
+ // and we still want a refresh attempt to populate the access token.
283
285
  const thresholdMs = 5 * 60 * 1000;
284
286
  const expires = sessionData.idpAccessTokenExpires || 0;
285
- const hasRefreshToken = !!sessionData.idpRefreshToken;
286
- const needsRefresh = hasRefreshToken && (!accessToken || (expires - Date.now()) <= thresholdMs);
287
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
288
+ const hasRefreshToken = !!(sessionData.idpRefreshToken || (sessionData as any).refreshToken);
289
+ const accessTokenStale = !accessToken || (expires - Date.now()) <= thresholdMs;
290
+ // If we already have a fresh access token, skip refresh entirely (no lock).
291
+ // If we don't, only attempt refresh when we have a refresh token to use.
292
+ const needsRefresh = accessTokenStale && hasRefreshToken;
287
293
 
288
294
  if (needsRefresh) {
289
295
  const refreshResult = await this.handleCoordinatedRefresh(req, token, sessionData, ctx);