• 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:

    • 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

    // Schedule refresh after receiving new tokens
    await scheduleTokenRefresh(3600); // 1 hour token
    console.log("Token refresh scheduled for shortly before expiration");
    export async function scheduleTokenRefresh(expiresIn: number): Promise<void> {
    const mod = await import("./storage/token-refresh");
    return mod.scheduleTokenRefresh(expiresIn);
    }