@singularlogic/coreplatts 0.0.3 → 0.0.4
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.js +17 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -280,10 +280,22 @@ function withValidToken(fn, accountsAPI) {
|
|
|
280
280
|
return Promise.resolve(fn.apply(this, args));
|
|
281
281
|
}
|
|
282
282
|
const now = Math.floor(Date.now() / 1e3);
|
|
283
|
-
let token = storage.getItem("
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
283
|
+
let token = storage.getItem("access_token");
|
|
284
|
+
let refreshToken = storage.getItem("refresh_token");
|
|
285
|
+
let exp = Number(storage.getItem("exp") || "0");
|
|
286
|
+
let refreshExp = Number(storage.getItem("refresh_exp") || "0");
|
|
287
|
+
if ((!exp || !refreshExp) && storage.getItem("id_token_claims_obj")) {
|
|
288
|
+
try {
|
|
289
|
+
const claims = JSON.parse(storage.getItem("id_token_claims_obj"));
|
|
290
|
+
if (claims.exp) exp = claims.exp;
|
|
291
|
+
if (claims.iat && claims.exp) {
|
|
292
|
+
const estimatedDuration = claims.exp - claims.iat;
|
|
293
|
+
refreshExp = claims.iat + 3 * estimatedDuration;
|
|
294
|
+
}
|
|
295
|
+
} catch (err) {
|
|
296
|
+
console.warn("\u26A0\uFE0F Could not parse id_token_claims_obj:", err);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
287
299
|
if (!token || now >= exp) {
|
|
288
300
|
if (!refreshToken || now >= refreshExp) {
|
|
289
301
|
console.warn("\u26A0\uFE0F Session expired. Please log in again.");
|
|
@@ -299,7 +311,7 @@ function withValidToken(fn, accountsAPI) {
|
|
|
299
311
|
const session = yield response.json();
|
|
300
312
|
const newExp = now + session.expires_in;
|
|
301
313
|
const newRefreshExp = now + session.refresh_expires_in;
|
|
302
|
-
storage.setItem("
|
|
314
|
+
storage.setItem("access_token", session.access_token);
|
|
303
315
|
storage.setItem("refresh_token", session.refresh_token);
|
|
304
316
|
storage.setItem("exp", String(newExp));
|
|
305
317
|
storage.setItem("refresh_exp", String(newRefreshExp));
|