//
// Copyright 2023 DXOS.org
//
import { useEffect, useState } from 'react';
import { useClient } from '@dxos/react-client';
export const useCredentials = ({ spaceKey }) => {
    const client = useClient();
    const spacesService = client?.services?.services?.SpacesService;
    if (!spacesService) {
        throw new Error('Client services not available.');
    }
    const [credentials, setCredentials] = useState([]);
    useEffect(() => {
        if (!spaceKey) {
            return;
        }
        const newCredentials = [];
        const stream = spacesService.queryCredentials({ spaceKey });
        stream.subscribe((credential) => {
            newCredentials.push(credential);
            setCredentials([...newCredentials]);
        });
        return () => {
            void stream.close();
        };
    }, [spaceKey?.toHex()]);
    return credentials;
};
//# sourceMappingURL=useCredentials.js.map