fix(auth): handle NaN clockDrift to fix token auto-refresh #14689
+397
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tip
Review each commit separately
NaNclockDrift valuesfetchAuthSession()does not auto-refresh expired tokens forCUSTOM_WITHOUT_SRPauth flowProblem
If
clockDriftwere to becomeNaN, the token expiration check would silently fail:This would cause expired tokens to never be detected as expired, preventing automatic refresh.
How clockDrift could become NaN
In
TokenStore.loadTokens(), clockDrift is parsed from storage:The nullish coalescing operator (
??) only handlesnull/undefined, not empty strings. IfclockDriftwere stored as""(empty string):?? '0'resultparseInt()resultnull'0'0✓'123''123'123✓''''(falsy!)NaN✗This could happen with custom
KeyValueStorageimplementations or if certain auth flows don't properly initialize theclockDriftvalue.Fix
Added defensive handling for
NaNclockDrift at multiple layers:||instead of??for fallback (NaN || 0 = 0vsNaN ?? 0 = NaN)NaNcheckRelated
🤖 Generated with Claude Code