Hiyve Components - v1.0.0
    Preparing search index...

    Props for CloudProvider

    Authentication can be provided in two ways (in order of preference):

    1. cloudToken - A short-lived token for browser-safe authentication
    2. generateCloudToken - A function that returns a cloudToken (recommended)
    interface CloudProviderProps {
        baseUrl?: string;
        children: ReactNode;
        cloudToken?: string;
        environment?: CloudEnvironment;
        generateCloudToken?: (
            params: GenerateCloudTokenParams,
        ) => Promise<string | CloudTokenResponse>;
        timeout?: number;
        userId?: string;
    }
    Index

    Properties

    baseUrl?: string

    Base URL for the cloud service (overrides environment if provided)

    children: ReactNode

    Children components

    cloudToken?: string

    Cloud token for browser-safe authentication.

    The token includes a ct_ prefix and is short-lived (default 24h). Obtain this from your backend server's cloud-token endpoint.

    const [cloudToken, setCloudToken] = useState<string>();

    useEffect(() => {
    fetch('/api/cloud-token', { method: 'POST' })
    .then(res => res.json())
    .then(data => setCloudToken(data.cloudToken));
    }, []);

    if (!cloudToken) return <Loading />;

    return <CloudProvider cloudToken={cloudToken}>...</CloudProvider>;
    environment?: CloudEnvironment

    Environment to connect to (optional). When omitted, auto-detected from the token response if generateCloudToken returns { cloudToken, environment }.

    generateCloudToken?: (
        params: GenerateCloudTokenParams,
    ) => Promise<string | CloudTokenResponse>

    Function to generate cloud tokens (recommended for browser)

    This function is called lazily on first request and automatically when the token expires. The SDK passes { userId } so your callback can forward it to the backend. Can return a plain string or { cloudToken, environment } for automatic environment detection.

    async function generateCloudToken({ userId }: { userId: string }) {
    const res = await fetch('/api/generate-cloud-token', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ userId }),
    });
    const { cloudToken, environment } = await res.json();
    return { cloudToken, environment };
    }

    <CloudProvider userId="user@example.com" generateCloudToken={generateCloudToken}>
    <App />
    </CloudProvider>
    timeout?: number

    Request timeout in milliseconds (optional)

    userId?: string

    The current user's email address.

    When omitted, automatically resolved from HiyveProvider's store (set when the user creates/joins a room). Pass explicitly only if you need cloud tokens before joining a room.