Skip to content

Commit 78ac26c

Browse files
author
Anatoli Kurtsevich
authored
Updated token renewal strategy to ask for a new token if the existing token expires in the next 60 secs (#96)
1 parent 489d547 commit 78ac26c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/credentials.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ class AccessToken {
4141
) {}
4242

4343
get isExpired() {
44-
const delta = Date.now() - this.createdOn;
45-
4644
// experiesIn stored in seconds
47-
return delta / 1000 >= this.experiesIn;
45+
const delta = (Date.now() - this.createdOn) / 1000;
46+
47+
// anticipate access token expiration by 60 seconds
48+
return delta + 60 >= this.experiesIn;
4849
}
4950
}
5051

0 commit comments

Comments
 (0)