@@ -88,7 +88,17 @@ export class NodeOAuthClientProvider implements OAuthClientProvider {
88
88
if ( tokens ) {
89
89
const expiresAt = new Date ( tokens . expires_at )
90
90
const now = new Date ( )
91
- const timeLeft = Math . round ( ( expiresAt . getTime ( ) - now . getTime ( ) ) / 1000 )
91
+ const expiresAtTime = expiresAt . getTime ( )
92
+ const timeLeft = ! isNaN ( expiresAtTime ) ? Math . round ( ( expiresAtTime - now . getTime ( ) ) / 1000 ) : 0
93
+
94
+ // Alert if expires_at produces an invalid date
95
+ if ( isNaN ( expiresAtTime ) ) {
96
+ await debugLog ( this . serverUrlHash , '⚠️ WARNING: Invalid expires_at detected while reading tokens ⚠️' , {
97
+ expiresAt : tokens . expires_at ,
98
+ tokenObject : JSON . stringify ( tokens ) ,
99
+ stack : new Error ( 'Invalid expires_at timestamp' ) . stack
100
+ } )
101
+ }
92
102
93
103
await debugLog ( this . serverUrlHash , 'Token result:' , {
94
104
found : true ,
@@ -114,7 +124,17 @@ export class NodeOAuthClientProvider implements OAuthClientProvider {
114
124
if ( DEBUG ) {
115
125
const expiresAt = new Date ( tokens . expires_at )
116
126
const now = new Date ( )
117
- const timeLeft = Math . round ( ( expiresAt . getTime ( ) - now . getTime ( ) ) / 1000 )
127
+ const expiresAtTime = expiresAt . getTime ( )
128
+ const timeLeft = ! isNaN ( expiresAtTime ) ? Math . round ( ( expiresAtTime - now . getTime ( ) ) / 1000 ) : 0
129
+
130
+ // Alert if expires_at produces an invalid date
131
+ if ( isNaN ( expiresAtTime ) ) {
132
+ await debugLog ( this . serverUrlHash , '⚠️ WARNING: Invalid expires_at detected in tokens ⚠️' , {
133
+ expiresAt : tokens . expires_at ,
134
+ tokenObject : JSON . stringify ( tokens ) ,
135
+ stack : new Error ( 'Invalid expires_at timestamp' ) . stack
136
+ } )
137
+ }
118
138
119
139
await debugLog ( this . serverUrlHash , 'Saving tokens' , {
120
140
hasAccessToken : ! ! tokens . access_token ,
0 commit comments