@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.
- package/dist/lib/api-handler.js +10 -4
- package/package.json +1 -1
- package/src/lib/api-handler.ts +10 -4
package/dist/lib/api-handler.js
CHANGED
|
@@ -183,12 +183,18 @@ class ApiHandler {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
catch { /* ignore */ }
|
|
186
|
-
// Check if token needs refresh
|
|
187
|
-
// Skip
|
|
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
|
-
|
|
191
|
-
const
|
|
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
package/src/lib/api-handler.ts
CHANGED
|
@@ -278,12 +278,18 @@ export class ApiHandler {
|
|
|
278
278
|
}
|
|
279
279
|
} catch { /* ignore */ }
|
|
280
280
|
|
|
281
|
-
// Check if token needs refresh
|
|
282
|
-
// Skip
|
|
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
|
-
|
|
286
|
-
const
|
|
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);
|