// Providers & sharing — live data from the vault-sharing API.
// Source: GET /api/v1/vault/sharing (returns active VaultSharing rows).
const Providers = () => {
const [tab, setTab] = React.useState('providers');
const [providers, setProviders] = React.useState(null);
const [error, setError] = React.useState(null);
React.useEffect(() => {
let dead = false;
(async () => {
try {
const r = await fetch(window.CHVault.apiRoot + '/api/v1/vault/sharing', {
credentials: 'include',
headers: { 'Accept': 'application/json' },
});
if (r.status === 404) { if (!dead) setProviders([]); return; }
if (!r.ok) throw new Error('sharing-' + r.status);
const j = await r.json();
if (!dead) setProviders(Array.isArray(j) ? j : (j.shares || j.providers || []));
} catch (e) {
if (!dead) { setError(e.message || String(e)); setProviders([]); }
}
})();
return () => { dead = true; };
}, []);
const renderProviders = () => (
{providers === null && (
Loading vault-sharing records…
)}
{providers && providers.length === 0 && (
No active provider grants.
When you authorize a clinic or clinician to read part of your vault, the grant will appear here with full scope detail. Revocation is one click and immediate.