• Gets or initializes the token expiry timestamp from memory or storage

    Retrieves the timestamp when the current access token expires using a memory-first strategy:

    1. Returns the in-memory timestamp if available for maximum performance
    2. Falls back to loading from persistent storage if not in memory

    The expiry timestamp is used to determine when to refresh tokens and if the current token is still valid for API requests.

    Returns null | number

    The token expiry timestamp (milliseconds since epoch) or null if not available

    // Check if token needs immediate refresh
    const expiry = getTokenExpiryState();
    if (expiry && expiry - Date.now() < 60000) {
    // Token expires in less than a minute, refresh now
    refreshAccessToken();
    }
    export function getTokenExpiryState(): number | null {
    if (tokenExpiryTimestamp) {
    return tokenExpiryTimestamp;
    }

    // Try to load from persistent storage
    return retrieveTokenValue<number>(TOKEN_EXPIRY_KEY);
    }