• Checks if the user is authenticated with valid tokens

    Performs a comprehensive authentication check that verifies:

    1. Both access and refresh tokens exist
    2. The access token has not expired

    This function serves as the definitive authority on authentication status throughout the application, providing a single source of truth for determining if the user can make authenticated requests.

    Returns boolean

    True if authenticated with valid tokens, false otherwise

    // Protect a feature that requires authentication
    if (isAuthenticated()) {
    // Show authenticated content
    showUserProfile();
    } else {
    // Show unauthenticated state
    showLoginButton();
    }
    export function isAuthenticated(): boolean {
    const accessToken = getAccessToken();
    const refreshToken = getRefreshToken();

    // Check if both tokens exist
    if (!accessToken || !refreshToken) {
    return false;
    }

    // Check if token has expired
    const expiry = getTokenExpiry();
    if (expiry && expiry <= Date.now()) {
    return false;
    }

    return true;
    }