Schedules a token refresh operation to occur shortly before
the access token expires. Dynamically imports the token
refresh module to avoid circular dependencies.
This function:
Calculates the optimal time to refresh (before expiry)
Sets up a timer to trigger refresh at the right moment
Ensures only one refresh timer is active at a time
Logs scheduling information for debugging
Handles timer creation errors gracefully
Parameters
expiresIn: number
Token lifetime in seconds
Returns Promise<void>
Promise resolving when refresh is scheduled
Example
// Schedule refresh after receiving new tokens awaitscheduleTokenRefresh(3600); // 1 hour token console.log("Token refresh scheduled for shortly before expiration");
Sets up automatic token refresh before expiry
Schedules a token refresh operation to occur shortly before the access token expires. Dynamically imports the token refresh module to avoid circular dependencies.
This function: