• Gets the token expiry timestamp

    Retrieves the access token expiration timestamp using a two-tier strategy:

    1. First attempts to get expiry from fast in-memory state
    2. Falls back to encrypted storage if not in memory
    3. When loading from storage, rehydrates memory state

    The expiry timestamp is used to determine when to refresh tokens and whether the current access token is still valid.

    Returns null | number

    Timestamp when the token expires (milliseconds since epoch) or null

    // Check if token needs refresh
    const expiryTime = getTokenExpiry();
    if (expiryTime) {
    const timeRemaining = expiryTime - Date.now();
    if (timeRemaining < 300000) { // Less than 5 minutes
    // Token expires soon, refresh it
    }
    }
    export function getTokenExpiry(): number | null {
    const expiry = getTokenExpiryState();
    if (expiry) return expiry;

    // If not in memory, try loading from encrypted storage
    const tokens = tokenStorage.loadTokens();
    if (tokens) {
    // Update memory state with loaded tokens
    setAccessTokenState(tokens.accessToken);
    setRefreshTokenState(tokens.refreshToken);
    setTokenExpiryState(tokens.expiresAt);
    return tokens.expiresAt;
    }

    return null;
    }