From 78ac26cdd75c3290eb6b7842447837303d21d729 Mon Sep 17 00:00:00 2001 From: Anatoli Kurtsevich Date: Tue, 15 Aug 2023 15:42:01 -0400 Subject: [PATCH] Updated token renewal strategy to ask for a new token if the existing token expires in the next 60 secs (#96) --- src/credentials.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/credentials.ts b/src/credentials.ts index 26a2f7d..97e7e3a 100644 --- a/src/credentials.ts +++ b/src/credentials.ts @@ -41,10 +41,11 @@ class AccessToken { ) {} get isExpired() { - const delta = Date.now() - this.createdOn; - // experiesIn stored in seconds - return delta / 1000 >= this.experiesIn; + const delta = (Date.now() - this.createdOn) / 1000; + + // anticipate access token expiration by 60 seconds + return delta + 60 >= this.experiesIn; } }