def token_verification(token):
    """
    Verifies the provided token with the Hugging Face API and retrieves user information.

    Args:
        token (str): The token to be verified. It can be either an OAuth token (starting with "hf_oauth")
                     or a regular token (starting with "hf_").

    Returns:
        dict: A dictionary containing user information with the following keys:
            - id (str): The user ID.
            - name (str): The user's preferred username.
            - orgs (list): A list of organizations the user belongs to.

    Raises:
        Exception: If the Hugging Face Hub is unreachable or the token is invalid.
    """
    if token.startswith("hf_oauth"):
        _api_url = config.HF_API + "/oauth/userinfo"
        _err_msg = "/oauth/userinfo"
    else:
        _api_url = config.HF_API + "/api/whoami-v2"
        _err_msg = "/api/whoami-v2"
    headers = {}
    cookies = {}
    if token.startswith("hf_"):
        headers["Authorization"] = f"Bearer {token}"
    else:
        cookies = {"token": token}
    try:
        response = requests.get(
            _api_url,
            headers=headers,
            cookies=cookies,
            timeout=3,
        )
    except (requests.Timeout, ConnectionError) as err:
        logger.error(f"Failed to request {_err_msg} - {repr(err)}")
        raise Exception(f"Hugging Face Hub ({_err_msg}) is unreachable, please try again later.")

    if response.status_code != 200:
        logger.error(f"Failed to request {_err_msg} - {response.status_code}")
        raise Exception(f"Invalid token ({_err_msg}). Please login with a write token.")

    resp = response.json()
    user_info = {}

    if token.startswith("hf_oauth"):
        user_info["id"] = resp["sub"]
        user_info["name"] = resp["preferred_username"]
        user_info["orgs"] = [resp["orgs"][k]["preferred_username"] for k in range(len(resp["orgs"]))]
    else:
        user_info["id"] = resp["id"]
        user_info["name"] = resp["name"]
        user_info["orgs"] = [resp["orgs"][k]["name"] for k in range(len(resp["orgs"]))]
    return user_info

    Verifies the provided token with the Hugging Face API and retrieves user information.

    Args:
        token (str): The token to be verified. It can be either an OAuth token (starting with "hf_oauth")
                     or a regular token (starting with "hf_").

    Returns:
        dict: A dictionary containing user information with the following keys:
            - id (str): The user ID.
            - name (str): The user's preferred username.
            - orgs (list): A list of organizations the user belongs to.

    Raises:
        Exception: If the Hugging Face Hub is unreachable or the token is invalid.
    
src/autotrain/app/utils.py