• Gets the current refresh token

    Retrieves the refresh token using a two-tier strategy:

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

    The refresh token is critical for maintaining long-term authentication by obtaining new access tokens when they expire.

    Returns null | string

    Current refresh token or null if not authenticated

    // Before attempting token refresh
    const refreshToken = getRefreshToken();
    if (refreshToken) {
    // Proceed with token refresh
    } else {
    // Cannot refresh, require re-authentication
    }
    export function getRefreshToken(): string | null {
    const refreshToken = getRefreshTokenState();
    if (refreshToken) return refreshToken;

    // 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.refreshToken;
    }

    return null;
    }